I'm working on an embedded platform (ARM) and have to be careful when dealing with bit patterns. Let's pretend this line is beyond my influence:
uint8_t foo = 0xCE; // 0b11001110
Interpreted as unsigned this would be 206. But actually it's signed, thus resembling -50. How can I continue using this value as signed?
int8_t bar = foo; // doesn't work
neither do (resulting in 0x10 or 0x00 for all input values)
int8_t bar = static_cast<int8_t>(foo);
int8_t bar = reinterpret_cast<int8_t&>(foo);
I just want the bits to remain untouched, ie. (bar == 0xCE)
Vice versa I'd be interested how to get bit-patters, representing negative numbers, into unsigned variables without messing the bit-pattern. I'm using GCC.