View Single Post
  #2   Spotlight this post!  
Unread 24-01-2004, 18:09
Jay Lundy Jay Lundy is offline
Programmer/Driver 2001-2004
FRC #0254 (The Cheesy Poofs)
Team Role: Alumni
 
Join Date: Jun 2001
Rookie Year: 2001
Location: Berkeley, CA
Posts: 320
Jay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to all
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).