Bug and fix for BitArray::toMemoryBlock

Unless I’m mistaken, there is a problem with toMemoryBlock in the BitArray class. Basically, if your bit array is an exact multiple of 8, plus one, it will ignore the highest bit.

Fix should be applied to BitArray, line 961

const MemoryBlock BitArray::toMemoryBlock() const throw() { const int numBytes = (getHighestBit() + 8) >> 3;

Previously it was using getHighestBit() + 7. Imagine the case of a BitArray instantiated using the default constructor, which will gives it 4 bytes, with the highest bit as 31. If you now added a new bit to it, it would be 5 bytes long, with a highest bit of 32. (32 + 7) >> 3 == 4, so the highest bit will be discarded.

Wow - you’re quite right! Thanks, will sort that out right away!