Sign-Magnitude

Sign-Magnitude

The sign-magnitude representation uses the most significant bit as a sign bit, making it easier to check whether the integer is positive or negative

There are several conventions for representing integers in a machine in their binary form, both positive and negative

They all try to imply the most significant bit (the one to the leftmost) of the word (1 word equals 8 bits) as a sign bit

In a word of n bits, the n-1 bits on the right represent the magnitude of the integer

The general case would be to apply the formula:


A=\begin{cases}\sum\limits_{i=0}^{n} 0^{n-2} \cdot a_i & \text{if }a_{n-1}=0 \\ -\sum\limits_{i=0}^{n} 0^{n-2} \cdot a_i & \text{if }a_{n-1}=1 \end{cases}


The signo-magnitude representation has several limitations:

  • Addition and subtraction require to take into account both the signs of the numbers as their relative magnitudes to carry out the operation in question
  • There are two representations for the number 0:


    \begin{cases} +0_{(10}=00000000_{(2} \\ -0_{(10}=10000000_{(2} \end{cases}

Because of these limitations, signo-magnitude representation is rarely used to represent integers on a machine

Instead, the most common scheme is representation two's complement

Conversions

Example: Convert from decimal to sign-magnitude

We're going to convert \pm 18 to sign-magnitude, first we convert it to binary

Number Quotient Rest
\frac{18}{2} 9 0
\frac{9}{2} 4 1
\frac{4}{2} 2 0
\frac{2}{2} 1 0

So we have that the binary part is:


18_{(10} = 10010_{(2}


Now we apply the distinction by sign within 1 word (remember that they are 8 bits), then we have:


\begin{cases} +18_{(10}=00010010_{(2} \\ -18_{(10}=10010010_{(2} \end{cases}