unsigned char vs signed char and range of values

I'm just making sure I understand how this works. If you have a byte repesenting an unsigned value (unsigned assumes absolute) then you can have 256 different values (2 raised to the 8) with a range of (0 - 255).

Now if you have a signed char, 2's compliment system makes it so that all of the non negative values can have both positive and negative values, correct? What is the maximum absolute value of a signed char (or any variable that is only a single byte). If you divide 256 / 2 you get 128, does that mean (0-127) is the range of values?

I'm pretty sure I understand this stuff, but I've been having problems with standards and file IOstreams and I'm wondering if something like this may be the source of the error.

thanks

Re: unsigned char vs signed char and range of values

Quote:

*Originally posted by Silvercord *

**I'm just making sure I understand how this works. If you have a byte repesenting an unsigned value (unsigned assumes absolute) then you can have 256 different values (2 raised to the 8) with a range of (0 - 255). **

Now if you have a signed char, 2's compliment system makes it so that all of the non negative values can have both positive and negative values, correct? What is the maximum absolute value of a signed char (or any variable that is only a single byte). If you divide 256 / 2 you get 128, does that mean (0-127) is the range of values?

An unsigned char is GUARANTEED to hold at least 0-255

A signed char is GUARANTEED to hold numbers from -127 to +127

In practice, with the 2's complimentary system and an 8-bit signed char results in the range -128 to +127 (an extra value which is not required who's 2's compliment is itself, similar to 0, -128).

A byte doesn't have to be 8-bits, however, we know that in practice it has to be *at least* 8-bits because of the ranges a char has to be capable of representing.

A char is neither defined to be signed or unsigned, it's implementation dependant.