BitSet to and from integer/long

Posted by ataylor on Stack Overflow See other posts from Stack Overflow or by ataylor
Published on 2010-03-18T21:56:01Z Indexed on 2010/03/18 22:11 UTC
Read the original article Hit count: 502

Filed under:
|
|

If I have an integer that I'd like to perform bit manipulation on, how can I load it into a java.util.BitSet? How can I convert it back to an int or long? I'm not so concerned about the size of the BitSet -- it will always be 32 or 64 bits long. I'd just like to use the set(), clear(), nextSetBit(), and nextClearBit() methods rather than bitwise operators, but I can't find an easy way to initialize a bit set with a numeric type.

© Stack Overflow or respective owner

Related posts about java

Related posts about bit-manipulation