On Monday 31 August 2009 17:18:36 David C. Rankin wrote:
On Monday 31 August 2009 03:30:11 pm Jim Cunning wrote: [...]
The fact that your program output included -62 (hex C2) immediately before the -80 leads me to believe that the encoding for the degree symbol in the C source is UTF-8. The byte sequence 0xc2 0xb0 would be the UTF-8 encoding for the degree symbol.
If you want to reduce some of your confusion when dealing with 8-bit character codes in C, you might consider always using "unsigned char" in place of "char". That way greater than or less than comparisons will work in a less confusing manner (though not necessarily exactly the same as lexical order, depending on character coding).
Thanks Jim:
With the unsigned char, the numbers get bigger ;-)
� 4294967234 � 4294967216
I also forgot to mention that when the compiler parses the printf format string, arguments corresponding to %d are promoted to (signed or unsigned) int. I don't remember where it's specified, but C normally does sign extension during integer coercion, so b'10110000' becomes b'11111111111111111111111111111011'. Thus, 4294967216 is the 32-bit unsigned equivalent of -80. You can change the output you get by adding " & 0xff" to every integer argument you really only want the lower 8 bits of. -- Jim