I am trying to deal with bits, which requires me to set a specific bit in an unsigned 64-bit integer. To set bit i , I run a bitwise OR with the bitmap in question with a left shifted number.
#include <stdint.h>
uint64_t kings = 0ULL;
kings |= 1 << i;
It works fine from bits 0 to bits 31, but does not work for bits 32 through 63. I suspect because the evaluation of the right side is in a 32-bit integer. So I tried a temporary variable.
uint64_t temp = 0ULL;
temp |= 1 << i;
Perhaps he still evaluates the right side as a 32-bit integer, or that this is another problem that I cannot understand. To print an integer, I use std :: bitset <64>. For instance:
uint64_t kings = 0ULL;
kings |= 1 << 3;
kings |= 1 << 59;
Expected Decimal Value: 576460752303423496
Actual: 8
std::bitset<64> x(kings);
std::cout << x;
: 000000000000000000000000000000000000000000000000000000000000000000000
, | = 1 < 3; .
, 32 63 ?