Logo Search packages:      
Sourcecode: randomsound version File versions  Download package

int bitbuffer_extract_bits ( BitBuffer  buf,
BitField bits,
int  count 

Extract some bits from a buffer.

Extract count of bits out of buf into bits.

This routine works least-significant-bit first so if you are only extracting one bit, it will be in bit zero of the BitField.

bufThe BitBuffer to extract from.
bitsA pointer to a BitField to put the bits in.
countThe number of bits to add to bits.
The number of bits actually added.

Definition at line 76 of file bitbuffer.c.

  int bits_to_extract = MIN(MIN(8, count), bitbuffer_available_bits(buf));
  int i;
  for (i = 0; i < bits_to_extract; ++i) {
    BitField subfield = buf->bits[BYTE_FOR_BIT(buf->firstused)];
    if (subfield & (1<<SHIFT_FOR_BIT(buf->firstused++)))
      *bits |= (1<<SHIFT_FOR_BIT(i));
      *bits &= ~(1<<SHIFT_FOR_BIT(i));
    if (buf->firstused == buf->size)
      buf->firstused = 0;
  buf->bitsused -= bits_to_extract;
  return bits_to_extract;

Generated by  Doxygen 1.6.0   Back to index