It works as it should. The char type has a size of 1 byte, which is 8 bits. If it is unsigned, all bits are used to store the value, which makes the maximum value that a char can contain 255 (2 8 = 256 different values, starting from 0).
In the case of signed char one bit is used to store the character instead of the value, which leaves you only 7 bits for the value, allowing you to store numbers from -128 to 127.
So, when you hold 255 in an unsigned char , all bits are interpreted as a value, so you have 255. If you convert it to signed char , the first bit starts to be treated as a sign bit, and the data in the variable starts to be interpreted as -1.
source share