當前位置: 首頁>>代碼示例>>C#>>正文


C# BitArray.appendBits方法代碼示例

本文整理匯總了C#中ZXing.Common.BitArray.appendBits方法的典型用法代碼示例。如果您正苦於以下問題:C# BitArray.appendBits方法的具體用法?C# BitArray.appendBits怎麽用?C# BitArray.appendBits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ZXing.Common.BitArray的用法示例。


在下文中一共展示了BitArray.appendBits方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: appendTo

 public override void appendTo(BitArray bitArray, byte[] text)
 {
    for (int i = 0; i < binaryShiftByteCount; i++)
    {
       if (i == 0 || (i == 31 && binaryShiftByteCount <= 62))
       {
          // We need a header before the first character, and before
          // character 31 when the total byte code is <= 62
          bitArray.appendBits(31, 5);  // BINARY_SHIFT
          if (binaryShiftByteCount > 62)
          {
             bitArray.appendBits(binaryShiftByteCount - 31, 16);
          }
          else if (i == 0)
          {
             // 1 <= binaryShiftByteCode <= 62
             bitArray.appendBits(Math.Min(binaryShiftByteCount, (short) 31), 5);
          }
          else
          {
             // 32 <= binaryShiftCount <= 62 and i == 31
             bitArray.appendBits(binaryShiftByteCount - 31, 5);
          }
       }
       bitArray.appendBits(text[binaryShiftStart + i], 8);
    }
 }
開發者ID:n1rvana,項目名稱:ZXing.NET,代碼行數:27,代碼來源:BinaryShiftToken.cs

示例2: CreateRawQR

        public static ByteMatrix CreateRawQR(byte[] rawData, ErrorCorrectionLevel errorCorrectionLevel)
        {
            int versionNumber = GetSmallestVersion(rawData.Length, errorCorrectionLevel);
            ZXing.QrCode.Internal.Version version = ZXing.QrCode.Internal.Version.getVersionForNumber(versionNumber);

            BitArray dataBits = new BitArray();
            foreach (byte b in rawData)
                dataBits.appendBits(b, 8);

            ZXing.QrCode.Internal.Version.ECBlocks ecBlocks = version.getECBlocksForLevel(errorCorrectionLevel);
            int bytesLength = version.TotalCodewords - ecBlocks.TotalECCodewords;
            terminateBits(bytesLength, dataBits);

            BitArray resultBits = interleaveWithECBytes(dataBits, version.TotalCodewords, bytesLength, ecBlocks.NumBlocks);

            ByteMatrix matrix = new ByteMatrix(version.DimensionForVersion, version.DimensionForVersion);
            int maskPattern = chooseMaskPattern(resultBits, errorCorrectionLevel, version, matrix);

            MatrixUtil.buildMatrix(resultBits, errorCorrectionLevel, version, maskPattern, matrix);
            return matrix;
        }
開發者ID:jefff,項目名稱:animalcrossingqr,代碼行數:21,代碼來源:StructuredAppendQR.cs

示例3: append8BitBytes

 internal static void append8BitBytes(String content, BitArray bits, String encoding)
 {
     byte[] bytes;
      try
      {
     bytes = Encoding.UTF8.GetBytes(content);
      }
      catch (Exception uee)
      {
     throw new WriterException(uee.Message, uee);
      }
      foreach (byte b in bytes)
      {
     bits.appendBits(b, 8);
      }
 }
開發者ID:cyberh0me,項目名稱:OTP,代碼行數:16,代碼來源:Encoder.cs

示例4: appendKanjiBytes

      internal static void appendKanjiBytes(String content, BitArray bits)
      {
         byte[] bytes;
         try
         {
            bytes = Encoding.GetEncoding("Shift_JIS").GetBytes(content);
         }
         catch (Exception uee)
         {
            throw new WriterException(uee.Message, uee);
         }
         int length = bytes.Length;
         for (int i = 0; i < length; i += 2)
         {
            int byte1 = bytes[i] & 0xFF;
            int byte2 = bytes[i + 1] & 0xFF;
            int code = (byte1 << 8) | byte2;
            int subtracted = -1;
            if (code >= 0x8140 && code <= 0x9ffc)
            {

               subtracted = code - 0x8140;
            }
            else if (code >= 0xe040 && code <= 0xebbf)
            {
               subtracted = code - 0xc140;
            }
            if (subtracted == -1)
            {

               throw new WriterException("Invalid byte sequence");
            }
            int encoded = ((subtracted >> 8) * 0xc0) + (subtracted & 0xff);
            bits.appendBits(encoded, 13);
         }
      }
開發者ID:Binjaaa,項目名稱:ZXing.Net.Mobile,代碼行數:36,代碼來源:Encoder.cs

示例5: appendAlphanumericBytes

      internal static void appendAlphanumericBytes(String content, BitArray bits)
      {
         int length = content.Length;

         int i = 0;
         while (i < length)
         {
            int code1 = getAlphanumericCode(content[i]);
            if (code1 == -1)
            {
               throw new WriterException();
            }
            if (i + 1 < length)
            {
               int code2 = getAlphanumericCode(content[i + 1]);
               if (code2 == -1)
               {
                  throw new WriterException();
               }
               // Encode two alphanumeric letters in 11 bits.
               bits.appendBits(code1 * 45 + code2, 11);
               i += 2;
            }
            else
            {
               // Encode one alphanumeric letter in six bits.
               bits.appendBits(code1, 6);
               i++;
            }
         }
      }
開發者ID:Binjaaa,項目名稱:ZXing.Net.Mobile,代碼行數:31,代碼來源:Encoder.cs

示例6: appendLengthInfo

 /// <summary>
 /// Append length info. On success, store the result in "bits".
 /// </summary>
 /// <param name="numLetters">The num letters.</param>
 /// <param name="version">The version.</param>
 /// <param name="mode">The mode.</param>
 /// <param name="bits">The bits.</param>
 internal static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits)
 {
    int numBits = mode.getCharacterCountBits(version);
    if (numLetters >= (1 << numBits))
    {
       throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
    }
    bits.appendBits(numLetters, numBits);
 }
開發者ID:Binjaaa,項目名稱:ZXing.Net.Mobile,代碼行數:16,代碼來源:Encoder.cs

示例7: interleaveWithECBytes

      /// <summary>
      /// Interleave "bits" with corresponding error correction bytes. On success, store the result in
      /// "result". The interleave rule is complicated. See 8.6 of JISX0510:2004 (p.37) for details.
      /// </summary>
      /// <param name="bits">The bits.</param>
      /// <param name="numTotalBytes">The num total bytes.</param>
      /// <param name="numDataBytes">The num data bytes.</param>
      /// <param name="numRSBlocks">The num RS blocks.</param>
      /// <returns></returns>
      internal static BitArray interleaveWithECBytes(BitArray bits,
                                             int numTotalBytes,
                                             int numDataBytes,
                                             int numRSBlocks)
      {
         // "bits" must have "getNumDataBytes" bytes of data.
         if (bits.SizeInBytes != numDataBytes)
         {

            throw new WriterException("Number of bits and data bytes does not match");
         }

         // Step 1.  Divide data bytes into blocks and generate error correction bytes for them. We'll
         // store the divided data bytes blocks and error correction bytes blocks into "blocks".
         int dataBytesOffset = 0;
         int maxNumDataBytes = 0;
         int maxNumEcBytes = 0;

         // Since, we know the number of reedsolmon blocks, we can initialize the vector with the number.
         var blocks = new List<BlockPair>(numRSBlocks);

         for (int i = 0; i < numRSBlocks; ++i)
         {

            int[] numDataBytesInBlock = new int[1];
            int[] numEcBytesInBlock = new int[1];
            getNumDataBytesAndNumECBytesForBlockID(
                numTotalBytes, numDataBytes, numRSBlocks, i,
                numDataBytesInBlock, numEcBytesInBlock);

            int size = numDataBytesInBlock[0];
            byte[] dataBytes = new byte[size];
            bits.toBytes(8 * dataBytesOffset, dataBytes, 0, size);
            byte[] ecBytes = generateECBytes(dataBytes, numEcBytesInBlock[0]);
            blocks.Add(new BlockPair(dataBytes, ecBytes));

            maxNumDataBytes = Math.Max(maxNumDataBytes, size);
            maxNumEcBytes = Math.Max(maxNumEcBytes, ecBytes.Length);
            dataBytesOffset += numDataBytesInBlock[0];
         }
         if (numDataBytes != dataBytesOffset)
         {

            throw new WriterException("Data bytes does not match offset");
         }

         BitArray result = new BitArray();

         // First, place data blocks.
         for (int i = 0; i < maxNumDataBytes; ++i)
         {
            foreach (BlockPair block in blocks)
            {
               byte[] dataBytes = block.DataBytes;
               if (i < dataBytes.Length)
               {
                  result.appendBits(dataBytes[i], 8);
               }
            }
         }
         // Then, place error correction blocks.
         for (int i = 0; i < maxNumEcBytes; ++i)
         {
            foreach (BlockPair block in blocks)
            {
               byte[] ecBytes = block.ErrorCorrectionBytes;
               if (i < ecBytes.Length)
               {
                  result.appendBits(ecBytes[i], 8);
               }
            }
         }
         if (numTotalBytes != result.SizeInBytes)
         {  // Should be same.
            throw new WriterException("Interleaving error: " + numTotalBytes + " and " +
                result.SizeInBytes + " differ.");
         }

         return result;
      }
開發者ID:Binjaaa,項目名稱:ZXing.Net.Mobile,代碼行數:89,代碼來源:Encoder.cs

示例8: makeVersionInfoBits

      /// <summary>
      /// Make bit vector of version information. On success, store the result in "bits" and return true.
      /// See 8.10 of JISX0510:2004 (p.45) for details.
      /// </summary>
      /// <param name="version">The version.</param>
      /// <param name="bits">The bits.</param>
      public static void makeVersionInfoBits(Version version, BitArray bits)
      {
         bits.appendBits(version.VersionNumber, 6);
         int bchCode = calculateBCHCode(version.VersionNumber, VERSION_INFO_POLY);
         bits.appendBits(bchCode, 12);

         if (bits.Size != 18)
         {
            // Just in case.
            throw new WriterException("should not happen but we got: " + bits.Size);
         }
      }
開發者ID:n1rvana,項目名稱:ZXing.NET,代碼行數:18,代碼來源:MatrixUtil.cs

示例9: testInterleaveWithECBytes

 public void testInterleaveWithECBytes()
 {
    byte[] dataBytes = {32, 65, 205, 69, 41, 220, 46, 128, 236};
    var @in = new BitArray();
    foreach (byte dataByte in dataBytes)
    {
       @in.appendBits(dataByte, 8);
    }
    var @out = Encoder.interleaveWithECBytes(@in, 26, 9, 1);
    byte[] expected =
       {
          // Data bytes.
          32, 65, 205, 69, 41, 220, 46, 128, 236,
          // Error correction bytes.
          42, 159, 74, 221, 244, 169, 239, 150, 138, 70,
          237, 85, 224, 96, 74, 219, 61,
       };
    Assert.AreEqual(expected.Length, @out.SizeInBytes);
    var outArray = new byte[expected.Length];
    @out.toBytes(0, outArray, 0, expected.Length);
    // Can't use Arrays.equals(), because outArray may be longer than out.sizeInBytes()
    for (int x = 0; x < expected.Length; x++)
    {
       Assert.AreEqual(expected[x], outArray[x]);
    }
    // Numbers are from http://www.swetake.com/qr/qr8.html
    dataBytes = new byte[]
       {
          67, 70, 22, 38, 54, 70, 86, 102, 118, 134, 150, 166, 182,
          198, 214, 230, 247, 7, 23, 39, 55, 71, 87, 103, 119, 135,
          151, 166, 22, 38, 54, 70, 86, 102, 118, 134, 150, 166,
          182, 198, 214, 230, 247, 7, 23, 39, 55, 71, 87, 103, 119,
          135, 151, 160, 236, 17, 236, 17, 236, 17, 236,
          17
       };
    @in = new BitArray();
    foreach (byte dataByte in dataBytes)
    {
       @in.appendBits(dataByte, 8);
    }
    @out = Encoder.interleaveWithECBytes(@in, 134, 62, 4);
    expected = new byte[]
       {
          // Data bytes.
          67, 230, 54, 55, 70, 247, 70, 71, 22, 7, 86, 87, 38, 23, 102, 103, 54, 39,
          118, 119, 70, 55, 134, 135, 86, 71, 150, 151, 102, 87, 166,
          160, 118, 103, 182, 236, 134, 119, 198, 17, 150,
          135, 214, 236, 166, 151, 230, 17, 182,
          166, 247, 236, 198, 22, 7, 17, 214, 38, 23, 236, 39,
          17,
          // Error correction bytes.
          175, 155, 245, 236, 80, 146, 56, 74, 155, 165,
          133, 142, 64, 183, 132, 13, 178, 54, 132, 108, 45,
          113, 53, 50, 214, 98, 193, 152, 233, 147, 50, 71, 65,
          190, 82, 51, 209, 199, 171, 54, 12, 112, 57, 113, 155, 117,
          211, 164, 117, 30, 158, 225, 31, 190, 242, 38,
          140, 61, 179, 154, 214, 138, 147, 87, 27, 96, 77, 47,
          187, 49, 156, 214,
       };
    Assert.AreEqual(expected.Length, @out.SizeInBytes);
    outArray = new byte[expected.Length];
    @out.toBytes(0, outArray, 0, expected.Length);
    for (int x = 0; x < expected.Length; x++)
    {
       Assert.AreEqual(expected[x], outArray[x]);
    }
 }
開發者ID:n1rvana,項目名稱:ZXing.NET,代碼行數:67,代碼來源:EncoderTestCase.cs

示例10: testToString

 public void testToString()
 {
    BitArray v = new BitArray();
    v.appendBits(0xdead, 16);  // 1101 1110 1010 1101
    Assert.AreEqual(" XX.XXXX. X.X.XX.X", v.ToString());
 }
開發者ID:n1rvana,項目名稱:ZXing.NET,代碼行數:6,代碼來源:BitVectorTestCase.cs

示例11: testAt

      public void testAt()
      {
         BitArray v = new BitArray();
         v.appendBits(0xdead, 16);  // 1101 1110 1010 1101
         Assert.IsTrue(v[0]);
         Assert.IsTrue(v[1]);
         Assert.IsFalse(v[2]);
         Assert.IsTrue(v[3]);

         Assert.IsTrue(v[4]);
         Assert.IsTrue(v[5]);
         Assert.IsTrue(v[6]);
         Assert.IsFalse(v[7]);

         Assert.IsTrue(v[8]);
         Assert.IsFalse(v[9]);
         Assert.IsTrue(v[10]);
         Assert.IsFalse(v[11]);

         Assert.IsTrue(v[12]);
         Assert.IsTrue(v[13]);
         Assert.IsFalse(v[14]);
         Assert.IsTrue(v[15]);
      }
開發者ID:n1rvana,項目名稱:ZXing.NET,代碼行數:24,代碼來源:BitVectorTestCase.cs

示例12: testXOR2

 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
 }
開發者ID:n1rvana,項目名稱:ZXing.NET,代碼行數:9,代碼來源:BitVectorTestCase.cs

示例13: testXOR

 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));
 }
開發者ID:n1rvana,項目名稱:ZXing.NET,代碼行數:9,代碼來源:BitVectorTestCase.cs

示例14: testAppendBitVector

 public void testAppendBitVector()
 {
    BitArray v1 = new BitArray();
    v1.appendBits(0xbe, 8);
    BitArray v2 = new BitArray();
    v2.appendBits(0xef, 8);
    v1.appendBitArray(v2);
    // beef = 1011 1110 1110 1111
    Assert.AreEqual(" X.XXXXX. XXX.XXXX", v1.ToString());
 }
開發者ID:n1rvana,項目名稱:ZXing.NET,代碼行數:10,代碼來源:BitVectorTestCase.cs

示例15: testNumBytes

 public void testNumBytes()
 {
    BitArray v = new BitArray();
    Assert.AreEqual(0, v.SizeInBytes);
    v.appendBit(false);
    // 1 bit was added in the vector, so 1 byte should be consumed.
    Assert.AreEqual(1, v.SizeInBytes);
    v.appendBits(0, 7);
    Assert.AreEqual(1, v.SizeInBytes);
    v.appendBits(0, 8);
    Assert.AreEqual(2, v.SizeInBytes);
    v.appendBits(0, 1);
    // We now have 17 bits, so 3 bytes should be consumed.
    Assert.AreEqual(3, v.SizeInBytes);
 }
開發者ID:n1rvana,項目名稱:ZXing.NET,代碼行數:15,代碼來源:BitVectorTestCase.cs


注:本文中的ZXing.Common.BitArray.appendBits方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。