Signed Numbers
Signed Numbers
Signed Numbers
Kershner
Binary Mathematics
Addition: this is performed using the same rules as decimal except all numbers are limited to
combinations of zeros (0) and ones (1).
1 11
0000 11102 which is 1410
+ 0000 01102 which is + 610
-------------------- -----------
0001 01002 2010
0001 01002 => we can ignore the leading zeros, since they have no impact on our conversion
What about negative numbers? Clearly not all numbers are positive.
Recall that adding a negative number is the equivalent to subtracting a positive number.
1
0 10 10 10
0001 10012 Æ 2510
- 0000 11102 Æ - 1410
-------------------- -----------
0000 10112 1110
THIS WAS PAINFUL!
Because there is so much borrowing, this is highly error prone for people.
For a computer to solve this math problem using standard subtraction rules, not only is circuitry needed to
deal with the subtraction, but additional circuitry would be needed to deal with all the complex borrowing.
Early Computer Scientists and Computer Engineers looked at this and determined that building this
complex circuitry would be expensive and the calculations would be slow, even in computer time,
because of all the borrowing.
An alternative technique was developed that enabled computer hardware to work with signed numbers
using slightly modified addition hardware. This technique is called two’s complement arithmetic.
Two’s Complement
Two’s complement is a way of representing negative numbers so that only addition hardware is required
by the computer.
Step 1: Decide how many bits you are going to use for all your operations.
For example: if we use 4-bits, this leaves only 3 bits to hold the number.
This limits our numbers to only very small ones.
A 4-bit number would look like XXXX the left-most bit is considered the sign bit
|
This is the sign bit
If we were using 8-bits the left-most bit will contain the sign. This would leave 7 bits to hold the number.
XXXX XXXX
|
This is the sign bit
This sign bit is reserved and is no longer one of the digits that make up the binary number. If the sign bit
is zero (0) the binary number following it is positive. If the sign bit is one (1) the binary number following it
is negative.
0000 1 0 1 12
(8) (2) (1) = 8 + 2 + 1 = 1110
This is exactly the same as writing out the powers of two, but we only need to remember the
values (which are all multiples of two) and can get more quickly to the end result.
1000 1 1 0 02
(8) (4) = 8 + 4 = 1210
Example:
1410 - 610 = 1410 + (- 610) = 810
Let’s use the number -6. How do we find the two’s complement of -6?
Example I:
Or
Step 3: Add the numbers together. In this case, add 1210 in binary (0000 11002) and the two’s
complement of - 910 in binary (1111 0111). Ignore any overflow.
1 11 1 1
1210 0000 11002
+ (-910) + 1111 01112
-------------- ------------------------
310 1 0000 00112
|
| this is the positive number 3 in binary
IGNORE
Overflow
IT Worked!
Example II:
2510 - 1410 = 1110
Or
Step 3: Add the numbers together. In this case, add 1210 in binary (0000 11002) and the two’s
complement of 910 in binary (1111 0111). Ignore any overflow.
1 11
2510 0001 10012
+ (-1410) + 1111 00102
-------------- ------------------------
1110 1 0000 10112
|
| this is the positive number 3 in binary
IGNORE
Overflow
IT Worked!
In all of the above examples, the resulting number, the answer was positive.
What happens if we are working with numbers where the result is negative?
The basic computational process is the same. Negative numbers are converted to their two’s
complement equivalent. But since the resulting number is negative, rather than positive, twos
complement is used again to convert the number back to standard binary.
Example III:
Step 4: Convert from two’s complement by doing the two’s complement process again.
Example IV:
- 25 + 18 = - 7
Proceed the same way, converting the negative number to it’s two’s complement equivalent.
Step 4: Convert from two’s complement by doing the two’s complement process again.
Solutions:
0001 0010
+ 1110 1010
-------------------------------
1111 1100
No Overflow
This is still in 2’s complement
Apply 2’s complement to number again
- 410
- 1210
- 1610
- 1310