public void AppendBit() { BitList bits = new BitList(); Assert.AreEqual(0, bits.Size); bits.AppendBit(true); Assert.AreEqual(1, bits.Size); Assert.AreEqual(true, bits[0]); bits.AppendBit(false); bits.AppendBit(true); Assert.AreEqual(3, bits.Size); Assert.AreEqual(false, bits[1]); Assert.AreEqual(true, bits[2]); }
/// <summary> /// Write termination section according 8.4.8 and 8.4.9 of JISX0510:2004 (p.24). /// </summary> public static void WriteTerminationSection(int dataBytesQty, BitList bits) { int capacity = dataBytesQty << 3; if (bits.Size > capacity) { throw new AzosException(StringConsts.ARGUMENT_ERROR + typeof(QREncoderMatrix).Name + ".writeTerminationSection(bits.Size>(dataBytesQty<<3))"); } for (int i = 0; i < 4 && bits.Size < capacity; ++i) { bits.AppendBit(false); } // Termination bits (JISX0510:2004 p.24 8.4.8) // Add padding bits when last byte isn't 8bit aligned int numBitsInLastByte = bits.Size & 0x07; if (numBitsInLastByte > 0) { for (int i = numBitsInLastByte; i < 8; i++) { bits.AppendBit(false); } } // According to JISX0510:2004 8.4.9 p.24 fill possible free space with pre-defined pattern int numPaddingBytes = dataBytesQty - bits.ByteSize; for (int i = 0; i < numPaddingBytes; ++i) { bits.AppendBits((i & 0x01) == 0 ? 0xEC : 0x11, 8); } if (bits.Size != capacity) { throw new AzosException(StringConsts.CODE_LOGIC_ERROR + typeof(QREncoderMatrix).Name + ".writeTerminationSection: bits.Size!=capacity"); } }
public void AppendOther() { const int SIZE0 = 13, SIZE1 = 33; BitList bits0 = new BitList(); for (int i = 0; i < SIZE0; i++) bits0.AppendBit(true); BitList bits1 = new BitList(); for (int i = 0; i < SIZE1; i++) bits1.AppendBit(true); bits0.AppendBitList(bits1); Assert.AreEqual( SIZE0 + SIZE1, bits0.Size); }
public void AppendOther() { const int SIZE0 = 13, SIZE1 = 33; BitList bits0 = new BitList(); for (int i = 0; i < SIZE0; i++) { bits0.AppendBit(true); } BitList bits1 = new BitList(); for (int i = 0; i < SIZE1; i++) { bits1.AppendBit(true); } bits0.AppendBitList(bits1); Assert.AreEqual(SIZE0 + SIZE1, bits0.Size); }
/// <summary> /// Write termination section according 8.4.8 and 8.4.9 of JISX0510:2004 (p.24). /// </summary> public static void WriteTerminationSection(int dataBytesQty, BitList bits) { int capacity = dataBytesQty << 3; if (bits.Size > capacity) throw new NFXException(StringConsts.ARGUMENT_ERROR + typeof(QREncoderMatrix).Name + ".writeTerminationSection(bits.Size>(dataBytesQty<<3))"); for (int i = 0; i < 4 && bits.Size < capacity; ++i) bits.AppendBit(false); // Termination bits (JISX0510:2004 p.24 8.4.8) // Add padding bits when last byte isn't 8bit aligned int numBitsInLastByte = bits.Size & 0x07; if (numBitsInLastByte > 0) for (int i = numBitsInLastByte; i < 8; i++) bits.AppendBit(false); // According to JISX0510:2004 8.4.9 p.24 fill possible free space with pre-defined pattern int numPaddingBytes = dataBytesQty - bits.ByteSize; for (int i = 0; i < numPaddingBytes; ++i) bits.AppendBits((i & 0x01) == 0 ? 0xEC : 0x11, 8); if (bits.Size != capacity) throw new NFXException(StringConsts.CODE_LOGIC_ERROR + typeof(QREncoderMatrix).Name + ".writeTerminationSection: bits.Size!=capacity"); }