cocos2d/external/android-specific/tremolo/Tremolo/bitwise.c
long oggpack_look(oggpack_buffer *b,int bits){
  unsigned long m=mask[bits];
  unsigned long ret = 0;
  int BITS = bits;

  if (!b->headptr) return 0;

  bits+=b->headbit;

  if(bits >= b->headend<<3){
    int            end=b->headend;
    unsigned char *ptr=b->headptr;
    ogg_reference *head=b->head;

    if(end<0)return 0;
    if (!head || !end)return 0;

    if(bits){
      _lookspan();
      ret=*ptr++>>b->headbit;
      if(bits>8){
        --end;
        _lookspan();
        ret|=*ptr++<<(8-b->headbit);
        if(bits>16){
          --end;
          _lookspan();
          ret|=*ptr++<<(16-b->headbit);
          if(bits>24){
            --end;
            _lookspan();
            ret|=*ptr++<<(24-b->headbit);
            if(bits>32 && b->headbit){
              --end;
              _lookspan();
              ret|=*ptr<<(32-b->headbit);
            }
          }
        }
      }
    }

  }else{

    /* make this a switch jump-table */
    ret=b->headptr[0]>>b->headbit;
    if(bits>8){
      ret|=b->headptr[1]<<(8-b->headbit);
      if(bits>16){
        ret|=b->headptr[2]<<(16-b->headbit);
        if(bits>24){
          ret|=b->headptr[3]<<(24-b->headbit);
          if(bits>32 && b->headbit)
            ret|=b->headptr[4]<<(32-b->headbit);
        }
      }
    }
  }

  ret&=m;
  //fprintf(stderr,
  //        "Look: buffer=(%d,%x,%d,%d) %02x%02x%02x%02x%02x%02x%02x%02x (%d bits) return=%x\n",
  //        b->headbit, b->headptr, b->headend, b->count,
  //        b->headptr[7], b->headptr[6], b->headptr[5], b->headptr[4],
  //        b->headptr[3], b->headptr[2], b->headptr[1], b->headptr[0],
  //        BITS, ret);
  //fflush(stderr);
  return ret;
}
/* Read in bits without advancing the bitptr; bits <= 32 */
Read in bits without advancing the bitptr; bits <= 32
Read in bits without advancing the bitptr ; bits < = 32
long oggpack_look(oggpack_buffer *b,int bits){
  unsigned long m=mask[bits];
  unsigned long ret = 0;
  int BITS = bits;
  if (!b->headptr) return 0;
  bits+=b->headbit;
  if(bits >= b->headend<<3){
    int            end=b->headend;
    unsigned char *ptr=b->headptr;
    ogg_reference *head=b->head;
    if(end<0)return 0;
    if (!head || !end)return 0;
    if(bits){
      _lookspan();
      ret=*ptr++>>b->headbit;
      if(bits>8){
        --end;
        _lookspan();
        ret|=*ptr++<<(8-b->headbit);
        if(bits>16){
          --end;
          _lookspan();
          ret|=*ptr++<<(16-b->headbit);
          if(bits>24){
            --end;
            _lookspan();
            ret|=*ptr++<<(24-b->headbit);
            if(bits>32 && b->headbit){
              --end;
              _lookspan();
              ret|=*ptr<<(32-b->headbit);
            }
          }
        }
      }
    }
  }else{
    ret=b->headptr[0]>>b->headbit;
    if(bits>8){
      ret|=b->headptr[1]<<(8-b->headbit);
      if(bits>16){
        ret|=b->headptr[2]<<(16-b->headbit);
        if(bits>24){
          ret|=b->headptr[3]<<(24-b->headbit);
          if(bits>32 && b->headbit)
            ret|=b->headptr[4]<<(32-b->headbit);
        }
      }
    }
  }
  ret&=m;
  return ret;
}
long oggpack_look ( oggpack_buffer * b , int bits ) { unsigned long m = mask [ bits ] ; unsigned long ret = 0 ; int BITS = bits ; if ( ! b -> headptr ) return 0 ; bits += b -> headbit ; if ( bits >= b -> headend << 3 ) { int end = b -> headend ; unsigned char * ptr = b -> headptr ; ogg_reference * head = b -> head ; if ( end < 0 ) return 0 ; if ( ! head || ! end ) return 0 ; if ( bits ) { _lookspan ( ) ; ret = * ptr ++ >> b -> headbit ; if ( bits > 8 ) { -- end ; _lookspan ( ) ; ret |= * ptr ++ << ( 8 - b -> headbit ) ; if ( bits > 16 ) { -- end ; _lookspan ( ) ; ret |= * ptr ++ << ( 16 - b -> headbit ) ; if ( bits > 24 ) { -- end ; _lookspan ( ) ; ret |= * ptr ++ << ( 24 - b -> headbit ) ; if ( bits > 32 && b -> headbit ) { -- end ; _lookspan ( ) ; ret |= * ptr << ( 32 - b -> headbit ) ; } } } } } } else { ret = b -> headptr [ 0 ] >> b -> headbit ; if ( bits > 8 ) { ret |= b -> headptr [ 1 ] << ( 8 - b -> headbit ) ; if ( bits > 16 ) { ret |= b -> headptr [ 2 ] << ( 16 - b -> headbit ) ; if ( bits > 24 ) { ret |= b -> headptr [ 3 ] << ( 24 - b -> headbit ) ; if ( bits > 32 && b -> headbit ) ret |= b -> headptr [ 4 ] << ( 32 - b -> headbit ) ; } } } } ret &= m ; return ret ; }
Read in bits without advancing the bitptr; bits <= 32
Read in bits without advancing the bitptr ; bits < = 32
/* make this a switch jump-table */ //fprintf(stderr, //        "Look: buffer=(%d,%x,%d,%d) %02x%02x%02x%02x%02x%02x%02x%02x (%d bits) return=%x\n", //        b->headbit, b->headptr, b->headend, b->count, //        b->headptr[7], b->headptr[6], b->headptr[5], b->headptr[4], //        b->headptr[3], b->headptr[2], b->headptr[1], b->headptr[0], //        BITS, ret); //fflush(stderr);