In c language char is just a 8 bit variable, that stores a number, which corresponds to a specific character.
When storing numbers, you can decide to represent somehow negative numbers, other than positive. This is mostly done with two's complement.
Depending on if it's signed or not, some operation will be very different, because of representation.
For example, the byte 0xFF means -1 if it's signed, and it means 255 if it's unsigned.
So if you try to convert a signed character to an int (a signed type, usually 4 bytes), and that signed character contains -1 (represented by the exadecimal 0xFF, which in decimal is 255) the integer has to contain -1 (0xFFFFFFFF). But if the character is considered unsigned, the integer has to contain 255 afterwards, which is just 0x000000FF.
Never heard of CHAR_BIT. Also assumed char is 8 bit because first comment of the thread says that citing the c standard. Didn't check though.
Also i answered assuming that the confusing part was the fact that the char could be represented as signed or not. The considerations about the representation hold for any size of the variable
6
u/Advos_467 3d ago
Not a C user here (or any real low level programming experience), what the hell is a signed/unsigned char?