Why is the range of signed byte is from -128 to 127 (2's complement) and not from -127 to 127?

后端 未结 5 1993

I read Why is the range of bytes -128 to 127 in Java? it says

128 is 10000000. Inverted, it\'s 01111111, and adding one gets 10000000 again

5条回答
  •  轮回少年
    2020-12-07 19:59

    Reason for why you cannot have range from to .

    It looks like and are represented by the same pattern. This is not good. A non-zero integer and its negative can't both be represented by the same pattern. So can not be represented in eight bits. The maximum positive integer that can be represented in eight bits is .

    What number is represented by 1000 0000? Add the representation of  to it:

    A good choice for ? is . Therefore 1000 0000 represents . Eight bits can be used to represent the numbers   ... 0 ... .

    For example, the range of integers that can be represented in eight bits using two's complement is:

    Notice that one more negative integer can be represented than positive integers.

    Source:- http://programmedlessons.org/AssemblyTutorial/Chapter-08/ass08_20.html

提交回复
热议问题