当前位置: 首页>>代码示例>>C#>>正文


C# BitArray.appendBit方法代码示例

本文整理汇总了C#中ZXing.Common.BitArray.appendBit方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.appendBit方法的具体用法?C# BitArray.appendBit怎么用?C# BitArray.appendBit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ZXing.Common.BitArray的用法示例。


在下文中一共展示了BitArray.appendBit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: testAppendBit

 public void testAppendBit()
 {
    BitArray v = new BitArray();
    Assert.AreEqual(0, v.SizeInBytes);
    // 1
    v.appendBit(true);
    Assert.AreEqual(1, v.Size);
    Assert.AreEqual(0x80000000L, getUnsignedInt(v, 0));
    // 10
    v.appendBit(false);
    Assert.AreEqual(2, v.Size);
    Assert.AreEqual(0x80000000L, getUnsignedInt(v, 0));
    // 101
    v.appendBit(true);
    Assert.AreEqual(3, v.Size);
    Assert.AreEqual(0xa0000000L, getUnsignedInt(v, 0));
    // 1010
    v.appendBit(false);
    Assert.AreEqual(4, v.Size);
    Assert.AreEqual(0xa0000000L, getUnsignedInt(v, 0));
    // 10101
    v.appendBit(true);
    Assert.AreEqual(5, v.Size);
    Assert.AreEqual(0xa8000000L, getUnsignedInt(v, 0));
    // 101010
    v.appendBit(false);
    Assert.AreEqual(6, v.Size);
    Assert.AreEqual(0xa8000000L, getUnsignedInt(v, 0));
    // 1010101
    v.appendBit(true);
    Assert.AreEqual(7, v.Size);
    Assert.AreEqual(0xaa000000L, getUnsignedInt(v, 0));
    // 10101010
    v.appendBit(false);
    Assert.AreEqual(8, v.Size);
    Assert.AreEqual(0xaa000000L, getUnsignedInt(v, 0));
    // 10101010 1
    v.appendBit(true);
    Assert.AreEqual(9, v.Size);
    Assert.AreEqual(0xaa800000L, getUnsignedInt(v, 0));
    // 10101010 10
    v.appendBit(false);
    Assert.AreEqual(10, v.Size);
    Assert.AreEqual(0xaa800000L, getUnsignedInt(v, 0));
 }
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:45,代码来源:BitVectorTestCase.cs

示例2: terminateBits

 /// <summary>
 /// Terminate bits as described in 8.4.8 and 8.4.9 of JISX0510:2004 (p.24).
 /// </summary>
 /// <param name="numDataBytes">The num data bytes.</param>
 /// <param name="bits">The bits.</param>
 internal static void terminateBits(int numDataBytes, BitArray bits)
 {
    int capacity = numDataBytes << 3;
    if (bits.Size > capacity)
    {
       throw new WriterException("data bits cannot fit in the QR Code" + bits.Size + " > " +
           capacity);
    }
    for (int i = 0; i < 4 && bits.Size < capacity; ++i)
    {
       bits.appendBit(false);
    }
    // Append termination bits. See 8.4.8 of JISX0510:2004 (p.24) for details.
    // If the last byte isn't 8-bit aligned, we'll add padding bits.
    int numBitsInLastByte = bits.Size & 0x07;
    if (numBitsInLastByte > 0)
    {
       for (int i = numBitsInLastByte; i < 8; i++)
       {
          bits.appendBit(false);
       }
    }
    // If we have more space, we'll fill the space with padding patterns defined in 8.4.9 (p.24).
    int numPaddingBytes = numDataBytes - bits.SizeInBytes;
    for (int i = 0; i < numPaddingBytes; ++i)
    {
       bits.appendBits((i & 0x01) == 0 ? 0xEC : 0x11, 8);
    }
    if (bits.Size != capacity)
    {
       throw new WriterException("Bits size does not equal capacity");
    }
 }
开发者ID:Binjaaa,项目名称:ZXing.Net.Mobile,代码行数:38,代码来源:Encoder.cs

示例3: toBitArray

 private static BitArray toBitArray(string bits)
 {
    var @in = new BitArray();
    var str = DOTX.Replace(bits, "");
    foreach (char aStr in str)
    {
       @in.appendBit(aStr == 'X');
    }
    return @in;
 }
开发者ID:n1rvana,项目名称:ZXing.NET,代码行数:10,代码来源:EncoderTest.cs

示例4: Encode

        public static byte[] Encode(byte[] Content, int Width, int Height)
        {
            var ecLevel = ErrorCorrectionLevel.L;
            var bits = new BitArray();

            var mode = Mode.BYTE;
            var bitsNeeded = 4 +
                mode.getCharacterCountBits(ZXing.QrCode.Internal.Version.getVersionForNumber(1)) +
                (Content.Length * 8);

            var version = ChooseVersion(bitsNeeded, out ecLevel);
            var ecBlocks = version.getECBlocksForLevel(ecLevel);
            var totalByteCapacity = version.TotalCodewords - ecBlocks.TotalECCodewords;
            var totalBitCapacity = totalByteCapacity << 3;

            // Write the mode marker (BYTE)
            bits.appendBits(mode.Bits, 4);

            // Write the number of bytes
            bits.appendBits(Content.Length, mode.getCharacterCountBits(version));

            // Write the bytes
            for (int i = 0; i < Content.Length; i++)
            {
                bits.appendBits(Content[i], 8);
            }

            // Terminate the bit stream
            //  - Write Termination Mode if space
            for (int i = 0; i < 4 && bits.Size < totalBitCapacity; ++i)
            {
                bits.appendBit(false);
            }

            // Add 8-bit alignment padding
            var bitsInLastByte = bits.Size & 0x07;
            if (bitsInLastByte > 0)
            {
                for (int i = bitsInLastByte; i < 8; i++)
                {
                    bits.appendBit(false);
                }
            }

            // Fill remain space with padding patterns
            var paddingBytes = totalByteCapacity - bits.SizeInBytes;
            for (int i = 0; i < paddingBytes; ++i)
            {
                bits.appendBits((i & 0x01) == 0 ? 0xEC : 0x11, 8);
            }

            // Interleave data bits with error correction code.
            var finalBits = interleaveWithECBytes(bits, version.TotalCodewords, totalByteCapacity, ecBlocks.NumBlocks);

            //  Choose the mask pattern and set to "qrCode".
            int dimension = version.DimensionForVersion;
            ByteMatrix matrix = new ByteMatrix(dimension, dimension);
            int maskPattern = chooseMaskPattern(finalBits, ecLevel, version, matrix);

            // Build the matrix and set it to "qrCode".
            MatrixUtil.buildMatrix(finalBits, ecLevel, version, maskPattern, matrix);

            // Render matrix to bytes
            return scaleMatrix(matrix.Array, Width, Height);
        }
开发者ID:garysharp,项目名称:Disco,代码行数:65,代码来源:QRCodeBinaryEncoder.cs

示例5: 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

示例6: stuffBits

      internal static BitArray stuffBits(BitArray bits, int wordSize)
      {
         var @out = new BitArray();

         // 1. stuff the bits
         int n = bits.Size;
         int mask = (1 << wordSize) - 2;
         for (int i = 0; i < n; i += wordSize)
         {
            int word = 0;
            for (int j = 0; j < wordSize; j++)
            {
               if (i + j >= n || bits[i + j])
               {
                  word |= 1 << (wordSize - 1 - j);
               }
            }
            if ((word & mask) == mask)
            {
               @out.appendBits(word & mask, wordSize);
               i--;
            }
            else if ((word & mask) == 0)
            {
               @out.appendBits(word | 1, wordSize);
               i--;
            }
            else
            {
               @out.appendBits(word, wordSize);
            }
         }

         // 2. pad last word to wordSize
         n = @out.Size;
         int remainder = n % wordSize;
         if (remainder != 0)
         {
            int j = 1;
            for (int i = 0; i < remainder; i++)
            {
               if ([email protected][n - 1 - i])
               {
                  j = 0;
               }
            }
            for (int i = remainder; i < wordSize - 1; i++)
            {
               @out.appendBit(true);
            }
            @out.appendBit(j == 0);
         }
         return @out;
      }
开发者ID:sjller,项目名称:ZXing.Net.Mobile,代码行数:54,代码来源:Encoder.cs

示例7: generateCheckWords

      private static BitArray generateCheckWords(BitArray stuffedBits, int totalSymbolBits, int wordSize)
      {
         var messageSizeInWords = (stuffedBits.Size + wordSize - 1) / wordSize;
         for (var i = messageSizeInWords * wordSize - stuffedBits.Size; i > 0; i--)
         {
            stuffedBits.appendBit(true);
         }

         var rs = new ReedSolomonEncoder(getGF(wordSize));
         var totalSizeInFullWords = totalSymbolBits / wordSize;
         var messageWords = bitsToWords(stuffedBits, wordSize, totalSizeInFullWords);
         rs.encode(messageWords, totalSizeInFullWords - messageSizeInWords);

         var startPad = totalSymbolBits % wordSize;
         var messageBits = new BitArray();
         messageBits.appendBits(0, startPad);
         foreach (var messageWord in messageWords)
         {
            messageBits.appendBits(messageWord, wordSize);
         }
         return messageBits;
      }
开发者ID:sjller,项目名称:ZXing.Net.Mobile,代码行数:22,代码来源:Encoder.cs


注:本文中的ZXing.Common.BitArray.appendBit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。