Search code examples
javabit-manipulationbitchess

Is there a way to use 1ULL in java?


So im making a chess engine in java, which involved a lot of bit operations, and I have been looking at some C code for some inspiration. In the code, he uses the print statement:

        for (int rank = 0; rank < 8; rank++){
        for (int file = 0; file < 8; file++) {

            int square = rank * 8 + file;
            printf("%d", (bitboard & (1ULL << sqaure)) ?1 :0 );

        }
    } 

The whole point of this method is that it loops through a long with 64 bits in it, and prints out an 8x8 square to represent a chessboard, with 1s for taken squares, and 0s for empty squares. Now I am familiar with everything in this code block, except 1ULL. What does it represent? Is there a way I can use this in java, or do I not even need to worry about it?


Solution

  • 1ULL is an unsigned long long - probably 64-bit. It means: The number '1', but as an unsigned long long. The unsigned part doesn't actually appear to matter, so, just.. 1L << square would do the job. (java also has this postfix letter thing, but only F, D, and L, for float, double, and long).