I'm programming a chess engine in Java and I would like to represent all pieces positions in one variable called bitmap or bitboard. In C++ I would simply use unsigned long, or so-called uint64_t. But because there are no unsigned variables in Java (as far as I know), what is some efficient way, how to implement this method?
I tried everything I was able to think of
Signedness doesn't actually make a significant difference to using numbers as bit masks -- at least, not in Java.
You can use a
longjust fine, even though it is signed.1L << 63works. Just note that you will want to use>>>instead of>>to when shifting your mask right.Note that if you want to store more than 64 bits, you may wish to use
java.util.BitSet, which is designed specifically as a bitmap that scales as necessary.