|
Re: problems assigning unsigned chars in FRC Code
Cast everything to int before printing. The reason is that printf assumes your variable is an int, and it reads from MSB to LSB.
So if you have a char with value 127 (01111111), then printf will start on the far left, and create an int that looks like 01111111 00000000. Everything is shifted up 8 bits, << 8 = * 2^8 = * 256.
If you cast to int first, the variable is padded with 0's, so 01111111 becomes 00000000 01111111.
By the way, I didn't look at the implementation to see why printf works this way. This is just what I'm assuming based on the problem (it's a common problem).
|