next up previous
Next: Sign(ed) 2's Complement Up: numbers Previous: Unsigned Binary

Sign(ed) Magnitude

In sign magnitude (or signed magnitude), the uppermost or most significant bit (msb) is referred to as the sign bit. The remaining $(k-1)$ bits are the size or magnitude of the number, with this bit string interpreted as a $(k-1)$ bit unsigned binary number. If the sign bit is zero, and all the other bits are zero, the the number is zero. If the sign bit is zero, and at least one other bit is non-zero, than the number is positive. If the sign bit is one, and at least one other bit is one, then the number is negative. The bit pattern with msb=1 and all other bits zero, is NOT negative zero; some machines adopt a ``large negative'' value for it, other machines make it illegal. We will treat it as an illegal bit pattern.

Using the notation from the previous section, we have:


\begin{displaymath}(b_k b_{k-1} b_{k-2}\ldots b_2 b_1 b_0)_2 = ((-1)^{b_k}\sum_{i=0}^{k-1} b_i 2^i)_{10}\end{displaymath}

The number $2087_{10}$ from the previous section requires 13 bits now: twelve to capture the size or magnitude of the number, and one, the msb, set to 0, to signify that the number is positive.


\begin{displaymath}(0\;\; 1000\;\;0010\;\; 0101)_2 =(-1)^0\;\; (1 \times 2^{11} + 1 \times 2^5 + 1 \times 2^2
+ 1 \times 2^0)_{10} \end{displaymath}

The negative of $2087_{10}$, given by $-2087_{10}$ matches the previous value in every bit but the msb, which is now 1 because we are representing a negative number.


\begin{displaymath}(1\;\; 1000\;\;0010\;\; 0101)_2 =(-1)^1 (1 \times 2^{11} + 1 \times 2^5 + 1 \times 2^2
+ 1 \times 2^0)_{10} \end{displaymath}

While this is a nice, logical way of implementing signed integers, if you attempt to add the representations for positive and negative 2087 in base 2, you don't get ``0'', which is the answer in base 10. So, when we want to do arithmetic, we need to move to yet another way of representing integers.


next up previous
Next: Sign(ed) 2's Complement Up: numbers Previous: Unsigned Binary
MM Hugue 2004-09-08