-3

I have a bitset and I want to check whether a bit at a specific index is zero or one.

Soul Enrapturer
  • 367
  • 2
  • 3
  • 14

1 Answers1

6

Just use .get():

return theSet.get(index);

It returns true if the bit is set and false otherwise.

Javadoc here

fge
  • 119,121
  • 33
  • 254
  • 329
  • +1 Technically, you don't need to know whether a 0 or 1 is used or something else. BitSet will tell you if the "bit" is *set or clear*. For example if you ask for a bit, beyond the size of the BitSet, e.g. `new BitSet(32).get(64)` will return false even though there is no 0 or 1 as such. – Peter Lawrey Jan 01 '13 at 12:50