You are using a C++03 compiler. In C++03, the bitset
constructor takes an unsigned long
parameter, which on your platform is 32 bits, so you lose the upper bits.
In C++11, this was changed to take an unsigned long long
, so your code would have worked. It would also work on a platform where long
is 64 bits.
You will need to use a different method to convert a 64-bit integer to a binary representation string or to a std::bitset
, for example a loop going over all bits.
You can also construct the bitset in two parts:
set::bitset<64> bs = (std::bitset<64>(val >> 32) << 32) |
std::bitset<64>(val & 0xffffffff);