In C, for an 8-bit two’s-complement signed char, the range of the char data…
2019
In C, for an 8-bit two’s-complement signed char, the range of the char data type is:
Answer: A. -128 to 127 — ConceptAn n-bit signed integer in two’s-complement form has the range −2n−1 through 2n−1−1. An 8-bit signed char therefore has 256 bit patterns: one bit…
- A.
-128 to 127
- B.
0 to 255
- C.
0 to 32767
- D.
None of these
Attempted by 53 students.
Show answer & explanation
Correct answer: A
Concept
An n-bit signed integer in two’s-complement form has the range −2n−1 through 2n−1−1. An 8-bit signed char therefore has 256 bit patterns: one bit carries the sign contribution, and the remaining bits determine the magnitude pattern.
Application
Set n = 8 because the question specifies an 8-bit signed char.
The minimum value is −28−1 = −27 = −128.
The maximum value is 28−1−1 = 27−1 = 127.
Cross-check and contrast
−128 to 127 contains 256 signed values and is the interval obtained from the 8-bit signed formula.
0 to 255 also contains 256 values, but it is the usual range of an 8-bit unsigned char.
0 to 32767 contains 32,768 non-negative values and corresponds to a 15-bit unsigned magnitude range, not an 8-bit range.
None of these would apply only if every listed interval failed the stated 8-bit signed assumption.
Therefore, the required range is −128 to 127.