Skip to content
Advertisement

Converting Long bitwise operations to BitSet bitwise operations

I’m trying to convert my code from using bitwise operations on Long type to the same operations on a BitSet, but I can’t find the right syntax.

This is the original code:

JavaScript

And this how I try to convert to BitSet:

JavaScript

I can’t find the right syntax for this line:

JavaScript

I did manage to use the and syntax (instead of &), but I can’t find out how to convert the left shift operation part to BitSet. (I am getting The operator & is undefined for the argument type(s) int, BitSet)

Advertisement

Answer

When using BitSet you don’t need to do the shifting and &ing yourself – the BitSet class has methods for this.

Also you could initialize your BitSet directly from a long constant.

Taking this together your code can look like this:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement