i performed a simple bit operation using <<
on the variable result
to set bit on the 32nd position..
result = result | (1<<31);
which should give the output as(in binary):
0000000000000000000000000000000010000000000000000000000000000000
and in decimal:
2147483648
but instead this was the output(in binary):
1111111111111111111111111111111110000000000000000000000000000000
and in decimal:
-2147483648
here is the code:
#include <bitset>
#include <iostream>
int main() {
int64_t result = 0;
result = result | (1 << 31);
std::bitset<64> x(result);
std::cout << x <<std:: endl;
std::cout << result << std:: endl;
}
please help me find the error
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…