示例#1
0
 public void WriteBits(int data, int numBits)
 {
     //copy lower x bit to buffer and flip buffer
     for (var needToWrite = numBits; needToWrite != 0;)
     {
         var capacity = encoding.BitsPerChar - bitsInBuffer;
         if (capacity == 0)
         {
             WriteBuffer();
             capacity = encoding.BitsPerChar;
         }
         if (needToWrite <= capacity)
         {
             buffer       |= (data << bitsInBuffer);
             bitsInBuffer += needToWrite;
             needToWrite   = 0;
         }
         else
         {
             var mask    = BitReversalTable.GetBitMask(capacity);
             var portion = (data & mask);
             var shifted = (portion << bitsInBuffer);
             buffer       |= shifted;
             data        >>= capacity;
             bitsInBuffer += capacity;
             needToWrite  -= capacity;
         }
     }
 }
示例#2
0
 public DataEncoding(
     int bitsPerChar,
     string codepage,
     IReadOnlyDictionary <char, int> reverseCodePage,
     BitReversalTable bitReversalTable)
 {
     BitsPerChar      = bitsPerChar;
     CodePage         = codepage;
     ReverseCodePage  = reverseCodePage;
     BitReversalTable = bitReversalTable;
 }
示例#3
0
 public static BitReversalTable GetTable(int bitWidth)
 {
     if (tableCache.TryGetValue(bitWidth, out var ret))
     {
         return(ret);
     }
     else
     {
         ret = new BitReversalTable(bitWidth);
         tableCache[bitWidth] = ret;
         return(ret);
     }
 }