c++ - Bit representation not being printed correctly for long int -
I am trying to represent some of the lengths of a long integer as a bitboard for my chess program of this variable I am using. However, the representation is not printed correctly. I am using the following code
zero displayboard () {bitsy The first two rows transform it into a binary presentation using the bitset class and print it However, when I try to do this by using code in the loop, then gives me the following output:
11111111111111110000000000000001111111111111110000000000000001
The right output is : 111111111111111100000000000000000001000000000000001111111111111111 fullBoard is the value that I am using: 0xFFFF00000000FFFF I am compiling using the following command: C ++ 11: G ++ board.cpp -std = c ++11 Why is this code incorrectly outputing? I do not think there is an error in the loop.
I think the problem is here: <
if (fullbirds & amp; (1 <> ) It can be:
if (fullBoard & Amp; (1ULL & lt; & lt ; I)) The reason for this is that 1 & lt; & Lt; I is evaluated as an int, which is probably 32 bits in your case, so UB once gets more than i 31. To create it, 1ULL < I expression is evaluated as 64 bit
Comments
Post a Comment