So, in accordance with this question, there are two ways to look at size BitSet.
size()which is outdated and not very useful. I agree with that. Size 64after completion:
BitSet b = new bitset (8);
length()which returns the index of the most significant bit. In the above example, length()will return 0. This is somewhat useful, but does not accurately reflect the number of bits that should be represented BitSetif you have leading zeros.
The information I'm dealing with rarely (if ever) evenly falls into 8-bit bytes, and the leading ones are 0just as important to me as 1s. I have data fields 333 bits long, some of which are 20, etc.
Is there a better way to handle bit level details in Java that will keep track of leading zeros? Otherwise, I will have to “give up my own,” so to speak. To which I already have a few ideas, but I would prefer not to reinvent the wheel, if possible.
source
share