Lesson Objective
- Know the difference between unsigned and signed binary (signed and magnitude).
- Know how to interpret and use two’s complement binary numbers.
- Understand methods used to add and subtract binary integers.
KS3, GCSE, A-Level Computing Resources
Signed Binary Numbers
Uses a sign bit to represent positive and negative numbers. They are more versatile than unsigned binary numbers, but unsigned binary numbers are often used when performance is critical.
Unsigned Binary Numbers
Does not have a sign bit, so they can only represent positive numbers.
8 bit Signed and Magnitude format.
In this system. Using 8 bits will mean the largest number you can represent is 127. The smallest value would be -127. The most significant bit/value is used to represent a + (0) or - (1).
-/+ | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |
---|---|---|---|---|---|---|---|---|
0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 3510 |
1 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | -3510 |
Can be represented using Signed Binary Values. The most significant bit/value is represented as a minus (-) number. The total amount of numbers you can assign (when using 8 bits) will still remain as 108 (256(-128 to 127)). The highest positive assignable value would be 127.
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |
---|---|---|---|---|---|---|---|---|
0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 3510 |
1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | -3510 |
Two's Complement Negative Number Conversion Examples
Let's say we want to represent -5 in 8-bit two's complement:
So, 11111011 is how -5 is represented in 8-bit two's complement.
Here is an example of converting the number 25 to -25.
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |
---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 2510 |
1 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | Flip |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | Add 1 |
1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | -2510 |
Unsigned binary the minimum and maximum values for a given number of bits, n, are 0 and 2n -1 respectively.
An 8 bit binary number ranges between (010 - 25510)
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |
---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 010 |
1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 25510 |
Most significant bit for 8 bits = 128
Zero is a positive number.
8 bits can be used to store 256 values. 255 is highest positive value.
You can carry out subtraction in Binary by using Two's Complement Notation. By adding a positive and negative signed binary number together you can perform a subtraction operation. The example below demonstrates the following operation 25 + -10 = 15.
2510 in binary.
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |
---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 2510 |
10 being turned into -10.
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |
---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1010 |
1 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | Flip |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | Add 1 |
1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | -1010 |
25 + -10 using standard binary addition rule.
-128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |
---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 2510 |
1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | -1010 |
0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1510 |