This only happens on a 64-bit system.
#include <iostream>
void printBits(unsigned long code) {
long bit = (sizeof(code) * 8) - 1;
std::cout << code << std::endl;
while (bit >= 0) {
bool value = code & (1 << bit--);
std::cout << value;
}
std::cout << std::endl;
}
int main() {
printBits(12345);
return 0;
}
Here's the output on a 64-bit system (repeated twice);
0000000000000000001100000011100100000000000000000011000000111001
Here's the output compiled with -m32
(correct);
00000000000000000011000000111001
What's the reason for this and how can I correct it?