Advertisement
kujikita

Untitled

Mar 27th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1.         byte BitRead = 0;
  2.         byte ValRead = 0;
  3.  
  4.         private byte[]  And = new byte[] { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF };
  5.         private byte[] IAnd = new byte[] { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0x00 };
  6.  
  7.         public byte ReadBit(byte Bits)
  8.         {
  9.             Bit = 0;
  10.             if (BitRead > 7)
  11.             { BitRead -= 8; if (BitRead != 0) Bit = (byte)((ValRead << BitRead) & And[Bits]);
  12.                 else Bit = 0; ValRead = (byte)stream.ReadByte();  }
  13.             Bit = (byte)((Bit | (ValRead >> (8 - BitRead - Bits))) & And[Bits]);
  14.             BitRead += Bits;
  15.             ValRead = (byte)((byte)(ValRead << BitRead) >> BitRead);
  16.             return Bit;
  17.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement