Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Stream decode(Stream src, int startbit, int bits)
- {
- MemoryStream res = new MemoryStream(bits / 8);
- int srcbit = startbit;
- int resbit = 0;
- byte a = srcbit == 0 ? (byte)0 : (byte)(src.ReadByte() >> srcbit);
- byte b = 0;
- while (bits-- > 0) {
- b >>= 1;
- if ((a & 1) != 0) b |= 0x80;
- a >>= 1;
- if (++srcbit == 8) {
- a = (byte)src.ReadByte();
- srcbit = 0;
- }
- if (++resbit == 8) {
- resbit = 0;
- res.WriteByte(b);
- }
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment