I am basically trying to do the following:
c[i] = ((number_to_store << pos) & 0xFF00000000) >> 32;
But this stores 0
in c[i]
something not expected. The following works like a charm:
c[i] = ((number_to_store << pos) & 0xFF000000) >> 24;
I am 99% sure the error has something to do with the fact all my variables are unsigned int
but here I am requesting 40 bits space.
Can someone please explain the differences between less than or equal to 32 bit and more than 32 bit number, when it's about bit manipulation?
edit: This also gives me 0:
cout << ((((unsigned long)number_to_store << (unsigned long)pos) & (unsigned long)0xFF00000000) >> 32) << endl;
edit 2: The following works:
cout << ((((unsigned long long)number_to_store << (unsigned long long)pos) & (unsigned long long)0xFF00000000) >> 32) << endl;
Lesson learned: never expect long to be larger than int