Guest User

Untitled

a guest
May 22nd, 2013
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1. static Stream decode(Stream src, int startbit, int bits)
  2. {
  3.     MemoryStream res = new MemoryStream(bits / 8);
  4.     int srcbit = startbit;
  5.     int resbit = 0;
  6.     byte a = srcbit == 0 ? (byte)0 : (byte)(src.ReadByte() >> srcbit);
  7.     byte b = 0;
  8.     while (bits-- > 0) {
  9.         b >>= 1;
  10.         if ((a & 1) != 0) b |= 0x80;
  11.         a >>= 1;
  12.  
  13.         if (++srcbit == 8) {
  14.             a = (byte)src.ReadByte();
  15.             srcbit = 0;
  16.         }
  17.         if (++resbit == 8) {
  18.             resbit = 0;
  19.             res.WriteByte(b);
  20.         }
  21.     }
  22.     return res;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment