The sign-magnitude binary format is the simplest conceptual format for expressing signed (positive and negative) integers. To represent a number in sign-magnitude, we simply use the leftmost bit to represent the sign, where 0 means positive and 1 means negative, and the remaining bits to represent the magnitude (absolute value).
A 8-bit sign-magnitude number would appear as follows:
To negate sign-magnitude numbers, simply toggle the sign bit. Note that this leads to having two representations for the number zero, +0 = 00000000 and -0 = 10000000.
What are the decimal values of the following 8-bit sign-magnitude numbers?
Represent the following in 8-bit sign-magnitude:
Addition and subtraction require attention to the sign bit. If the signs are the same, we simply add the magnitudes as unsigned numbers and watch for overflow. If the signs differ, we subtract the smaller magnitude from the larger, and keep the sign of the larger.
Since the magnitude is an unsigned binary integer, range is computed as it is for unsigned binary, but with one bit fewer. Hence, for 8-bit sign-magnitude, the magnitude is a 7-bit unsigned integer and the range is therefore +/-27-1. In general, the range of an N-bit sign-magnitude number is +/-2N-1-1.
Comparison works as with unsigned binary if the signs are the same. If the signs differ, the positive value is larger.
Perform the following conversions.
11111111 8-bit SM to decimal
01111111 8-bit SM to decimal
-7 decimal to 8-bit SM