Saurabh
Saurabh

Reputation: 121

How to calculate total number of bits in BitSet object?

I want to calculate the total number of bits in a BitSet object. The method length returns the "logical size" of the BitSet: the index of the highest set bit in the BitSet plus one, while method cardinality will give the total number of bits set to 1 in the object.

I want to calculate the total number of bits including both 0s and 1s. How do I do that?

Upvotes: 1

Views: 1242

Answers (3)

sgowd
sgowd

Reputation: 2262

The site shows how to convert a BitSet to binary String. Then just calculate the string.length()

Upvotes: -1

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272517

How about BitSet.size()?.....

Upvotes: 2

Related Questions