S
shaun roe
As a follow up to my question about STL and bitset<64> I'd like to share
a quirk (bug?) about unsigned long long support and the bitset. I'm
using gcc 3.2 on linux or gcc 3.3 on mac, the answer is the same.
unsigned long long int f;
f=3;
bitset<64> g(f);
cout << f << endl;
cout << g << endl;
f<<=32;
bitset<64> h(f);
g<<=32; // h and g should be the same now
cout << "f is 3 << 32: "<< f << endl;
cout << "g is (bitset<64>(3)) << 32: "<<g<< endl;
cout << "h is bitset<64>( 3 << 32): "<<h<< endl;
gives:
f is 3 << 32: 12884901888
g is (bitset<64>(3)) << 32:
0000000000000000000000000000001100000000000000000000000000000000
h is bitset<64>( 3 << 32):
0000000000000000000000000000000000000000000000000000000000000000
i.e. I cant initialise a bitset<64> from a long long: it loses the top
32 bits. But having initialised the lower bits, I can left shift them
upwards...I guess this is not very surprising, given the presently
patchy support for 64 bit ints, but still could be a nasty trap in some
situations.
a quirk (bug?) about unsigned long long support and the bitset. I'm
using gcc 3.2 on linux or gcc 3.3 on mac, the answer is the same.
unsigned long long int f;
f=3;
bitset<64> g(f);
cout << f << endl;
cout << g << endl;
f<<=32;
bitset<64> h(f);
g<<=32; // h and g should be the same now
cout << "f is 3 << 32: "<< f << endl;
cout << "g is (bitset<64>(3)) << 32: "<<g<< endl;
cout << "h is bitset<64>( 3 << 32): "<<h<< endl;
gives:
f is 3 << 32: 12884901888
g is (bitset<64>(3)) << 32:
0000000000000000000000000000001100000000000000000000000000000000
h is bitset<64>( 3 << 32):
0000000000000000000000000000000000000000000000000000000000000000
i.e. I cant initialise a bitset<64> from a long long: it loses the top
32 bits. But having initialised the lower bits, I can left shift them
upwards...I guess this is not very surprising, given the presently
patchy support for 64 bit ints, but still could be a nasty trap in some
situations.