There is no "128" in the signed byte. Range
- 0 to 127: 128 values
- -1 to -128: 128 values
A total of 256 values, i.e. 2 ^ 8.
Adding based on the comment (and re-reading the question)
0x80 could be considered -128 or +128. Wikipedia explanation is worth reading
Two additions of the minimum number in the range will not have the desired effect of negating the number.
For example, two -128 additions on an 8-bit system result in the same binary number. This is because a positive value of 128 cannot be represented with an 8-bit binary binary digit. Note that this is detected as an overflow condition, since the transfer was performed, but not from the most significant bit. This can lead to unexpected errors in the fact that an uncontrolled implementation of an absolute value can return a negative number in the case of a minimum negative value. The abs integer family in C usually has this behavior. This is also true for Java. In this case, the developer must decide whether to check the minimum negative value before calling the function.
The most negative number in two additions is sometimes called the "strange number" because it is the only exception. Although the number is an exception, it is a valid number in the regular two complement systems. All arithmetic operations work with it both as an operand and (if there was no overflow) the result.
In addition, the processor that propagates MSb (bit 7) to the right will have the right shift of the signed integer, which will be against simple logic if 0x80 is +128, because after just one shift we get 0xC0 , which is a negative number (-64) ... (while the right shift from a positive number usually cannot give a negative result).
Ring Ø
source share