/// <summary> /// Make bit vector of type information. On success, store the result in "bits" and return true. /// Encode error correction level and mask pattern. See 8.9 of /// JISX0510:2004 (p.45) for details. /// </summary> /// <param name="ecLevel">The ec level.</param> /// <param name="maskPattern">The mask pattern.</param> /// <param name="bits">The bits.</param> public static void makeTypeInfoBits(ErrorCorrectionLevel ecLevel, int maskPattern, BitArray bits) { if (!QRCode.isValidMaskPattern(maskPattern)) { throw new WriterException("Invalid mask pattern"); } int typeInfo = (ecLevel.Bits << 3) | maskPattern; bits.appendBits(typeInfo, 5); int bchCode = calculateBCHCode(typeInfo, TYPE_INFO_POLY); bits.appendBits(bchCode, 10); BitArray maskBits = new BitArray(); maskBits.appendBits(TYPE_INFO_MASK_PATTERN, 15); bits.xor(maskBits); if (bits.Size != 15) { // Just in case. throw new WriterException("should not happen but we got: " + bits.Size); } }
public void testXOR() { var v1 = new BitArray(); v1.appendBits(0x5555aaaa, 32); var v2 = new BitArray(); v2.appendBits(-1431677611, 32); // 0xaaaa5555 v1.xor(v2); Assert.AreEqual(0xffffffffL, getUnsignedInt(v1, 0)); }
public void testXOR2() { var v1 = new BitArray(); v1.appendBits(0x2a, 7); // 010 1010 var v2 = new BitArray(); v2.appendBits(0x55, 7); // 101 0101 v1.xor(v2); Assert.AreEqual(0xfe000000L, getUnsignedInt(v1, 0)); // 1111 1110 }
public void testXOR() { { BitArray v1 = new BitArray(); v1.appendBits(0x5555aaaa, 32); BitArray v2 = new BitArray(); v2.appendBits(-1431677611, 32); // 0xaaaa5555 v1.xor(v2); Assert.AreEqual(0xffffffffL, getUnsignedInt(v1, 0)); } { BitArray v1 = new BitArray(); v1.appendBits(0x2a, 7); // 010 1010 BitArray v2 = new BitArray(); v2.appendBits(0x55, 7); // 101 0101 v1.xor(v2); Assert.AreEqual(0xfe000000L, getUnsignedInt(v1, 0)); // 1111 1110 } }