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

int transfer_bits_and_debias ( BitBuffer  from,
BitBuffer  to 
)

Transfer bits from one buffer to another, debiassing en-route.

Performing a von-neumann debiassing, transfer bits from the from BitBuffer to the to BitBuffer.

This method of debiassing will produce at absolute maximum, a drop of 50% in the bitcount. I.E. at minimum you will lose one bit in two.

In actuality, in a truly random stream, you will lose three bits in four, which means that the debiassing will leave you with around one quarter the number of bits you started with.

Parameters:
fromThe BitBuffer to extract bits from.
toThe BitBuffer to add debiassed bits to.
Returns:
The number of bits added to to.

Definition at line 9 of file debias.c.

{
  BitField bits;
  int bits_xfered = 0;
  while (bitbuffer_available_bits(from) >= 2) {
    if (bitbuffer_extract_bits(from, &bits, 2) != 2)
      return bits_xfered;
    if ((bits & 3) == 1 || (bits & 3) == 2) {
      if (bitbuffer_add_bits(to, bits, 1) != 1)
        return bits_xfered;
      bits_xfered++;
    }
  }
  return bits_xfered;
}

Generated by  Doxygen 1.6.0   Back to index