4

What are examples of signed and unsigned decimal values? What are the differences between them?

JRN
  • 6,691
Bilis
  • 125

3 Answers3

3

Computers used a set of bits to represent numbers. Signed and unsigned numbers are two different ways of mapping bits to numbers. Here is an example for 8 bits:

$$\begin{array} {c|c|c} \text{Bits} & \text{Unsigned Number} & \text{Signed Number} \\ \hline 0000\,0000 & 0 & 0 \\ 0000\,0001 & 1 & 1 \\ 0000\,0010 & 2 & 2 \\ 0000\,0011 & 3 & 3 \\ \vdots & \vdots & \vdots \\ 0111\,1110 & 126 & 126 \\ 0111\,1111 & 127 & 127 \\ 1000\,0000 & 128 & -128 \\ 1000\,0001 & 129 & -127 \\ \vdots & \vdots & \vdots \\ 1111\,1110 & 254 & -2 \\ 1111\,1111 & 255 & -1 \\ \end{array}$$

Suppose an unsigned number $U$ and a signed number $S$ have the same $n$ bit pattern. Then notice that: $$U \equiv S \pmod{2^n}$$

As a result, $A + B \pmod{2^n}$, $A - B \pmod{2^n}$, and $A \times B \pmod{2^n}$, can be computed the with the same circuit regardless of whether $A$ and $B$ are signed or not.

The differences between signed and unsigned numbers occur when:

  • Converting the bit pattern to a string (you have to know whether a number is signed or not to correctly print the value of $1111\,1110$, for example)
  • Comparing two values: which is larger, $0111\,1111$ or $1000\,0000$? It depends on whether they are signed or not
  • Division
  • Sometimes a signed bit shift to the right is preferred to pad the left with the MSB rather than with zero
DanielV
  • 24,386
1

A signed value uses one bit to specify the sign (i.e. $-$ or $+$) whereas an unsigned value does not.

For example, $-127$ and $+127$ are both signed while $255$ and $0$ are unsigned.

  • but 255 is +ve right? why not 255 is signed? – Bilis Aug 13 '14 at 07:09
  • Yes, but the sign is not explicitly mentioned. You don't need to dedicate a bit to specify the sign and when you don't specify the sign, the value is assumed to be positive. $+255$ would be a signed value, but this would require 9 bits (1 for the sign and 8 for the number 255).$255$ is an unsigned value requiring only 8 bits. – Pranav Marathe Aug 13 '14 at 14:54
  • Sure, no problem. – Pranav Marathe Aug 14 '14 at 05:11
1

Consider an 8 bit value like that:

b7 b6 b5 b4 b3 b2 b1 b0

If this value is unsigned you cannot express negative values. Therefore, you can only express values between $0$ and $2^8-1=+255$. (If you use n bits then this range is between $0$ and $2^n-1$)

If this value is signed then b7 bit is used to determine the sign and you can express negative values. The value of the expressed number is positive if b7 is $0$ and negative if b7 is $1$. Since you are using one bit to determine the sign, you have to express values using 7 bits (b6...b0). Therefore the range is between $-2^7$ and $+2^7-1$.

For example:

"00001001"=+9

You should know 2's complement to express -9

"10111000"=-9

However, if you use unsigned notation then "10111000"=+184.

I hope you understand.