Unsigned char is 1 byte long..
it's range is from -128 to 127
Most significant bit is sign bit to indicate whether the char has positive or negative value and the rest 7 bits are meant for storing the actual value of char... so the max +ve value of char can be 127 as expected but in the -ve side how can it be -128 ???
himanjim 0 Junior Poster in Training
Recommended Answers
Jump to Post— Ancient Dragon 5,2430xFF is the largest value that can be stored in one byte, for signed integers that is 0xFF/2, which is 127.5 (use a calculator if you must). Since you can put 0.5 in a byte, one side is 127 and the other is 128 so that 127+128 = 255 (0xFF).
…
Jump to Post— Infarction 503The reason that it's -128 and 127 breaks down like this: You have 8 bits. One of them is for sign. That leaves 7 bits for the value, or 128 values. One side is 0 to 127. Since you already have 0, the other half is -1 to -128.
Jump to Post— Infarction 503Read up on how Two's Complement works and hopefully you'll see. It comes down to 0 being counted as a positive number, and 1-127+0 is a total of 128 numbers; there's an equal …
Jump to Post— Dave Sinkula 2,398Unsigned char is 1 byte long..
it's range is from -128 to 127At least; it can be larger.
Most significant bit is sign bit to indicate whether the char has positive or negative value and the rest 7 bits are meant for storing the actual value of char... so …
All 15 Replies
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Infarction 503 Posting Virtuoso
himanjim 0 Junior Poster in Training
Infarction 503 Posting Virtuoso
Dave Sinkula 2,398 long time no c Team Colleague
Infarction 503 Posting Virtuoso
Dave Sinkula 2,398 long time no c Team Colleague
himanjim 0 Junior Poster in Training
Narue 5,707 Bad Cop Team Colleague
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Infarction 503 Posting Virtuoso
Narue 5,707 Bad Cop Team Colleague
goutham_see 1 Newbie Poster
Dave Sinkula 2,398 long time no c Team Colleague
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.