changing unsigned to signed actually seems to do the trick, but I don't know why
1 2 3 4 5 6
typedefunsignedlonglong ulong;
ulong c = numeric_limits<ulong>::max();
cout << "size of ulong == " << sizeof(c) << endl;
cout << " c == " << c << endl;
cout << bitset<64>((signed)c) << endl; // now it works, but probably not for the right reasons
}
size of ulong == 8
c == 18446744073709551615
1111111111111111111111111111111111111111111111111111111111111111
As far as the original code goes, I assume it's MinGW doing something dumb and not implementing the bitset constructor correctly. (This wouldn't be the first time MinGW, especially a relatively old version, isn't supporting the standard correctly.)
Do you have the link to where you downloaded this version of MinGW from? My guess would be that if you dug into the actual library implementation, it's narrowing the unsigned long long into the old unsigned long version.
#include <iostream>
#include <bitset>
#include <limits>
usingnamespace std;
int main()
{
unsignedlonglong c = numeric_limits<unsignedlonglong>::max();
cout << "size of ulong == " << sizeof(c) << endl;
cout << " c == " << c << endl;
cout << bitset<64>(c) << endl;
cout << bitset<64>((unsigned)c) << endl;
}
size of ulong == 8
c == 18446744073709551615
1111111111111111111111111111111111111111111111111111111111111111
0000000000000000000000000000000011111111111111111111111111111111