[英]Converting from long to BitSet - what is the meaning of these bitwise operations?
[英]Conversion from long to BitSet and left shift operations
我尝试将以下代码从 long 转换为 BitSet:
private static void createOptions(int bit1, int bit2, int bit3, ArrayList<long[]> moves) {
moves.add(new long[]{(1L << bit1), (1L << bit2) | (1L << bit3),
(1L << bit1) | (1L << bit2) | (1L << bit3)});
moves.add(new long[]{(1L << bit3), (1L << bit2) | (1L << bit1),
(1L << bit1) | (1L << bit2) | (1L << bit3)});
}
private static void createOptions(int bit1, int bit2, int bit3, ArrayList<BitSet[]> moves) {
// How can I do a bitwise left-shift with BitSet?
}
但是在 Java BitSet 中似乎没有按位左移操作。 我能做什么?
以下将使用long[2]
。
class Bits128 {
long[] bits = new long[2];
void shift(int n) {
n %= 64;
if (n > 0) {
bits[1] <<= n;
bits[1] |= bits[0] >> (64 - n);
bits[0] <<= n;
}
if (n < 0) ...
}
boolean isSet(int i) {
bits[i/64] & (1L << (i % 64)) != 0;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.