converting char to unsigned long
When I try to convert a char to an unsigned long, the unsigned long is padded with 1's instead of 0's if the char is >=128. For example:
1 2 3 4 5 6 7 8 9 10
|
char c;
unsigned long ul;
c = 0x59;
ul = (unsigned long) c;
// now ul==0x00000059
c = 0x89;
ul = (unsigned long) c;
// now ul==0xffffff89
|
But when I am using 'unsigned char', this does not happen. Aren't chars unsigned by default? Is this a bug?
A signed char
can have as maximum value 127, 0x89 is 137 so it becomes -119.
-119ul is 0xffffff89ul
But I am using char, not signed char ...
They are either signed by default or it is left to the compiler.
Topic archived. No new replies allowed.