Why has a byte may represent a range of signed integer is -128 to + 127?

Why is -127 to 128?

  For a byte, it can be represented by an integer Why not -127 + 127, -127 + 128 not, but -128 to + 127

  For unrelated signed integer and specific programming language, but by the hardware, the easiest way we can think of is to use one of the symbols representing the remaining seven bits used to represent data.

 

  However, this method has a flaw, there is two +0 and -0 0, data can only represent -127 + 127, while two bits are used in combination with a digital representation wasteful, complement good solution this problem.

  First, a representation of a positive number, and the same method as described above, but the negative first symbol position 1, represented negative. The remaining 7 bits of data and said representation are very different.

  Subtracting bits from a combination of a negative composition 9 10000000 (unsigned binary), the value is the negative number.

  

  Similarly, 10000001 -127 can be expressed as:

   Thus a byte can already explain why the number of symbols that can be represented with a range of -128 to +127.

 

  Meanwhile, if you want to take the anti-complement binary, it only needs to invert each bit plus one. For example, 1 is 10000000, 11111110 -1 + 1 so that 11111111 is seen in front, and the same.

Guess you like

Origin www.cnblogs.com/Dylan7/p/12649972.html