3.3.2 Converting Between Number Bases
Table of Contents
1 Converting Between Number Bases
Learn It
Converting Between Number Bases
- Different numbering systems exist for whole numbers, fractions, positive numbers and negative numbers. At GCSE level, you need only work with binary integers that have a decimal equivalent of between 0 and 255.
Binary to Decimal Conversion
- To convert a binary number into decimal, add up the column values
where a
1
appears. - For example, to convert the binary number
01101100
to decimal, write each number under a column heading, starting on the right with the least significant digit:
27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
---|---|---|---|---|---|---|---|
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 1 | 1 | 0 | 1 | 1 | 0 | 0 |
This gives us the value: 64 + 32 + 8 + 4 = 108
More Examples:
Decimal | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|---|---|---|
126 <--- | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
213 <--- | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
255 <--- | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
Try It
Binary Game
- Try playing the binary game using the link below:
Badge It
- Silver: Convert the following binary numbers into decimal.
1. 00010111 2. 10010110 3. 11111111
Learn It
Decimal to Binary Conversions
- To convert a decimal number to a binary number, use the column headings. You need to find the highest column heading that you can take away from the number and start there.
- To convert the decimal number
57
into binary. - The highest column heading we can take out of 57 is 32 (The next one
is 64, too high):
- We can start by placing a
1
in the column headed32
(57 - 32 = 25). - We can then place a
1
in the column headed 16 (25 - 16 = 9). - Finally place
1s
in the columns8
and1
(9 - 8 = 1).
- We can start by placing a
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|---|---|
0 | 0 | 1 | 1 | 1 | 0 | 0 | 1 |
- This gives us the value: 57 = 00111001
Here are some more examples:
Decimal | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
---|---|---|---|---|---|---|---|---|
23 —> | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 1 |
84 —> | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 |
255 —> | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
- You will notice in the examples above that we always write the binary numbers using eight bits.
- This is common practise, it is not incorrect to write the first binary value as 10111 rather than 00010111 (Without the leading zeros), but the second example is more commonly used as values are often stored in bytes.
Badge It
- Gold: Convert the following decimal numbers into binary.
1. 19 2. 63 3. 142
Learn It
Hexadecimal Number System
- As mentioned previously, humans are not very good at remembering
long strings of numbers. For example which of these are easier to
remember:
0110111
or6F
- So to make it easier, we can represent every group of 4 bits (Nibble) with a single digit.
- The smallest value you can hold in 4 bits is
0000
. The largest value is1111
. This means that we need to represent the decimal values 0 to 15 with a single digit. - As we only have 10 single digits in decimal (0 to 9), so to get around this proble we use uppercase letters A to F for the remaining six digits.
- The following table shows the hexadecimal digits and their decimal equivalents:
Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Hexadecimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
Useful Conversion Table
Decimal | Binary | Hexadecimal |
---|---|---|
0 | 0000 | 0 |
1 | 0001 | 1 |
2 | 0010 | 2 |
3 | 0011 | 3 |
4 | 0100 | 4 |
5 | 0101 | 5 |
6 | 0110 | 6 |
7 | 0111 | 7 |
8 | 1000 | 8 |
9 | 1001 | 9 |
10 | 1010 | A |
11 | 1011 | B |
12 | 1100 | C |
13 | 1101 | D |
14 | 1110 | E |
15 | 1111 | F |
16 | 0001 0000 | 10 |
255 | 1111 1111 | FF |
Note for above table
- Decimal Number 15 - A single digit replaces 4 bits, 15 is the biggest number you can have with 4 bits.
- Decimal Number 16 - So 16 is one group of 16 and no units.
- Decimal Number 255 - 255 is 15 groups of 16 + 15 units i.e. ((15 x 16) + 15 = 240 + 15).
Hexadecimal Explained
- The following video explains how hexadecimal number systems work.
Learn It
Converting Binary/Decimal to Hexadecimal
- In GCSE computing you will only need to work with 8-bit binary numbers, which can be represented as two hex digits.
- The left-hand hex digit represents groups of 16, the right-hand hex digits represents the units.
- For example, to convert
- There are several methods for converting Decimal to Hexadecimal:
- Method 1: Convert to Binary/Hex
- Using the tables and video above try and convert the following decimal
number:
112
first into Binary and then into Hexadecimal? - Step 1: First we need to use the binary table to work out the Binary number.
- Step 2: Does 128 go into 112? No, so we place a 0 under the 128 value, then does 64 go into 112? Yes, 112 - 64 = 48 - so we place a 1 under the 64 value.
- Step 3: We can then check does 32 goes into 48? Yes, 48 - 32 = 16 - so we place a 1 under the 32 value.
- Step 4: Repeat this until there is no remainder.
27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
---|---|---|---|---|---|---|---|
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
- This gives us 01110000 - We then need to split the byte (8 bits) into two nibbles (4 bits).
- Then starting at the least significant bit (The right side).
- Read the 4 bits (0000) - Look at the conversion table above gives us
a
0
. - Read the next 4 bits (0111) - Again look at the coversion table
gives us a
7
. - So
112
in Decimal converts to01110000
in Binary - Converts to 70 in Hexadecimal. - Method 2: Divide by 16
- To convert the decimal number
182
into hex the first step is to work out how many groups of 16 there are in 182. - Secondly work out how many units are left over.
182 / 16 = 11 remainder 6
11
isB
in hex,6
is just6
, so182
in decimal =B6
hex.- Method 3: Denary as a Middle Step
- With experience, you'll not need a table, as you'll come to recognise the hex equivalent for each nibble.
- However, if you don't have a conversion table or can't remember the values, you can convert between binary and hex, by using denary as a middle step.
- Lets start with the binary number
01011101
- Split it into nibbles -
0101 1101
- Convert to denary -
1*1 + 0*2 + 1*4 + 0*8
and =1*1 + 0*2 + 1*4 + 1*8
- So we get -
5
and13
- Now convert to Hex -
5
andD
- So the Hex is 5D
Learn It
Converting Hexadecimal to Binary/Decimal
Converting Hexadecimal to Binary
- Converting a hexadecimal number into binary is a simple matter of converting each hex digit into a group of 4 binary digits. To convert the hex number A7 to binary:
- Use the Binary Conversion table above to look at the four left-hand
binary digits that represent the hex number A —> 1010 and then
look at the next four binary digits that represent the hex number
7 ---> 0111
. - So the hex number
A7
can be represented by the binary value10100111
More Examples:
B5 ---> 1011 0101
FA ---> 1111 1010
Converting Hexadecimal to Decimal
- To convert a hexadeicmal number into decimal, multiply the heading
or place value by the hex digit value, to convert the hex number
A7
to decimal. (Remember column place values are: 16 and 1, and A = 10) - A = (10 x 16) + 7 = (7 x 1) = 167
More Examples:
- 7F —> 112 + 15 = 127
- CD —> 192 + 13 = 205
Badge It
- Platinum: Conplete the following conversions:
Convert the following numbers from binary to hex: 1. 00010111 2. 11111100 3. 00110010 4. 11011100
Convert the following numbers from decimal to hex: 1. 77 2. 255 3. 186 4. 18
Convert the following hexadecimal numbers into binary: 1. E4 2. 8A 3. FF 4. C1
Convert the following hexadecimal numbers into decimal: 1. 77 2. AF 3. 17 4. 20
Uses of hexadecimal
- Hex numbers are expressed more compactly than binary numbers, and are much easier to understand and remember.
- For this reason, hexadecimal numbers are often used instead of binary numbers and have several applications in computing.
- One application you are probably familiar with is picking colours for a graphic.
- Hex numbers are also used in assembly language instructions such as ADD &4F3A.