Why the range of char in c is from -128 to 127?

for my computer, the char type hold 8-bits.
I know the first digit is for the sign, the max number in bin is 0111 1111 111 11111, I know this eauals 2^7 - 1 = 127,
the min number in bin is 1000 0000 0000 0000. but why this number equals -128, I think the first number is a sign, and it shouldn't count, why count the whole digits and then negative it?
I know the first digit is for the sign
It's generally not.

http://en.wikipedia.org/wiki/Two%27s_complement
Last edited on
It's generally not.

What do you mean by that ?
In 2's complement, the MSB of a signed integer always indicates the sign.
What do you mean by that ?


Whoops. You are correct there.
the min number in bin is 1000 0000 0000 0000. but why this number equals -128

There's no use for -0 so Two's complement... err... just go and read firedraco's link.
standard wrote:
Objects declared as characters (char) shall be large enough to store any member of the implementation’s basic character set. If a character from this set is stored in a character object, the integral value of that character object is equal to the value of the single character literal form of that character. It is implementation-defined whether a char object can hold negative values. Characters can be explicitly declared unsigned or signed. Plain char, signed char, and unsigned char are three distinct types. A char, a signed char, and an unsigned char occupy the same amount of storage and have the same alignment requirements (3.11); that is, they have the same object representation. For character types, all bits of the object representation participate in the value representation. For unsigned character types, all possible bit patterns of the value representation represent numbers. These requirements do not hold for other types. In any particular implementation, a plain char object can take on either the same values as a signed char or an unsigned char; which one is implementation-defined.


The point being that a char might also actually be unsigned char.
Topic archived. No new replies allowed.