Confusion over a 16-bit data range

In the 16-bit C compiler, we have 2 bytes for storing an integer and 1 byte for a character. For unsigned integers, the range is from 0 to 65535. For unsigned integers, the range is from -32768 to 32767. For unsigned characters, from 0 to 255. According to the integer type, there should not be a signed range of characters from -128 to 127. But why -127 to 127? What about the remaining bit?

+5
source share
1 answer

I think you are mixing two things:

  • Which corresponds to the standard for signed char, intetc.
  • Currently, most hardware is implemented .

, - , .

C , SCHAR_MIN SCHAR_MAX, ( ) , :

SCHAR_MIN  -127
SCHAR_MAX  +127

. 255 , 256.

, , , "" , . .. [-128,+127] . 2 , [-128,+127] - , .

, int, C, . :

INT_MIN    -32767
INT_MAX    +32767

. 65535 , 65536.

, 2 , , [-32768,+32767].

2 256 8 (.. [-128,+127]), , .

- , :

00000000
10000000

, .. 0 (, +0 -0).

, . , - -127 (11111111) +127 (01111111) 8 .

(, ):

00000000
11111111

, .. 0.

, -127 (10000000) +127 (01111111) 8 .

C , [-128,+127], , , , C. , 8 9 . , , : C [-127,+127] . , . int.

+15

All Articles