You want a new byte array large enough to hold all the values from 0 to 0xffffffff inclusive. You are using this as a bitmap, where each value uses 1 bit. Instead of writing false-true-false-true-false-true-false-true, you can write 01010101 and be sure to squeeze those 8 boolean values into 8 bits (1 byte).
So to fit all the values from 0 to 0xffffffff in, you need not 0xffffffff bits, but 0x20000000. That is 0xffffffff / 8.
Joined: Oct 13, 2005
I earlier wrote: . . . 0x20000000. That is 0xffffffff / 8.
Try it and see. You will see that 0xffffffff / 8 is 0x20000000 0x1fffffff.
So, either my interpretation of 0 to 0xffffffff is mistaken, or the arithmetic is mistaken and it should read 0xffffffff / 8 + 1.
Actually, it is bad style to write numbers out like that. It would have been better to write
TOTAL_NUMBER_OF_BITS / BITS_PER_BYTE + (TOTAL_NUMBER_OF_BITS % BITS_PER_BYTE == 0 ? 0 : 1)