home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / macutils.lzh / MACUTILS / MACUNPACK / bits_be.c < prev    next >
C/C++ Source or Header  |  1995-09-18  |  947b  |  47 lines

  1. #include "../util/masks.h"
  2. #include "bits_be.h"
  3.  
  4. unsigned int bit_be_bitbuf;
  5. char *bit_be_filestart;
  6. int bit_be_inbytes;
  7.  
  8. static unsigned int bit_be_subbitbuf;
  9. static int bit_be_bitcount;
  10.  
  11. void bit_be_fillbuf(n)  /* Shift bit_be_bitbuf n bits left, read n bits */
  12. int n;
  13. {
  14.     bit_be_bitbuf <<= n;
  15.     while (n > bit_be_bitcount) {
  16.     bit_be_bitbuf |= bit_be_subbitbuf << (n -= bit_be_bitcount);
  17.     if(bit_be_inbytes == 0) {
  18.         bit_be_subbitbuf = 0;
  19.     } else {
  20.         bit_be_subbitbuf = *bit_be_filestart++ & BYTEMASK;
  21.         bit_be_inbytes--;
  22.     }
  23.     bit_be_bitcount = 8;
  24.     }
  25.     bit_be_bitbuf |= bit_be_subbitbuf >> (bit_be_bitcount -= n);
  26.     bit_be_bitbuf &= WORDMASK;
  27. }
  28.  
  29. unsigned int bit_be_getbits(n)
  30. int n;
  31. {
  32.     unsigned int x;
  33.  
  34.     x = bit_be_bitbuf >> (BITBUFSIZ - n);
  35.     bit_be_fillbuf(n);
  36.     return x;
  37. }
  38.  
  39. void bit_be_init_getbits()
  40. {
  41.     bit_be_bitbuf = 0;
  42.     bit_be_subbitbuf = 0;
  43.     bit_be_bitcount = 0;
  44.     bit_be_fillbuf(BITBUFSIZ);
  45. }
  46.  
  47.