AQA 7517, section 4.5.4.1
Unsigned and signed binary
Unsigned binary can represent only zero and positive whole numbers. Every bit contributes to the size of the number, and there is no way to show a negative.
Signed binary uses some of the bit patterns to represent negative numbers as well (see 4.5.4.3). The same bit pattern means different things in the two systems. For example, the 8-bit pattern 11111111 is 255 in unsigned binary but in two's complement signed binary.
Place values
Each place is worth double the one to its right.
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 |
Adding the place values where there is a 1: .
Converting unsigned binary to decimal
Add up the place values of the 1s.
Converting decimal to unsigned binary
Work from the largest place value down. Write 1 if it fits and subtract it, otherwise write 0.
Convert 77 to 8-bit binary.
| Place | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Fits? | no | yes (77 − 64 = 13) | no | no | yes (13 − 8 = 5) | yes (5 − 4 = 1) | no | yes (1 − 1 = 0) |
| Bit | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 |
You can also divide by 2 repeatedly and read the remainders from the bottom up (see 4.5.2.1).
Minimum and maximum values
With bits, there are different patterns. In unsigned binary these represent the numbers from 0 to :
| Bits () | Minimum | Maximum |
|---|---|---|
| 4 | 0 | |
| 8 | 0 | |
| 16 | 0 | |
| 32 | 0 |
The maximum is when every bit is 1. For 8 bits, . This is one less than because 0 takes one of the 256 patterns.
If a number is bigger than the maximum, it can't be stored in that many bits. This is an overflow (see 4.5.4.2).
Worked example
Task: (a) convert to decimal. (b) Convert 200 to 8-bit unsigned binary. (c) What is the largest number that fits in 12 bits?
- (a) .
- (b) , so the bits are .
- (c) .
Exam tip: state the number of bits in your answer, and pad with leading zeros if the question gives a word length (for example 00001101 for 13 in 8 bits). The largest value in bits is , not .
Check yourself
What is the difference between unsigned and signed binary?
Unsigned binary can only represent zero and positive numbers. Signed binary can also represent negative numbers.
Convert to decimal
.
What are the minimum and maximum unsigned values for 10 bits?
0 and .
Convert 100 to 8-bit unsigned binary
, so .