With the likelihood of GCC that unsigned values ββare two additions, even on an embedded platform.
Then the 8-bit number 0xCE represents 0xCE-256 .
Since the two additions are really just modulo 2 n where n is the number of bits in the view.
EDIT : hm, for my sake it is better to give a concrete example:
int8_t toInt8( uint8_t x ) { return (x >= 128? x - 256 : x); }
EDIT 2 : I have not seen the final question of how to get a bit pattern into an unsigned variable. It is very simple: just assign. The result is guaranteed by the C ++ standard, namely, that the stored value is congruent (in time equal to one) equal to the destination, modulo 2 n .
Cheers and hth.,
Cheers and hth. - alf
source share