Converting Between Bases

Now we know about different bases such as binary (base 2), decimal (base 10), and hexadecimal (base 16), we will learn how to convert between these different bases. Converting between these bases means we can take a number written in one number system and write it in another.

This is important if we want to be able to, for example, work with emedded systems, or convert colours written as decimal RGB (red, green, blue) values to hexadecimal.

Watch the video and then answer the questions below.

Six-minute video

You can also view this video on YouTube


Key Points

Decimal to Binary

To convert from decimal to binary, we repeatedly divide by 2. Each time, the remainder becomes the next least significant binary digit. We divide by 2 because we converting into base 2 (binary). To convert into hexadecimal, use the same process, but instead of dividing by 2, divide by 16. If we wanted to convert into base n we would divide by n.

See the example below, where we show how to convert 140 from decimal into binary, getting the answer 10001100.

140 / 2 = 70 r 0
70  / 2 = 35 r 0
35  / 2 = 17 r 1
17  / 2 = 8  r 1
8   / 2 = 4  r 0
4   / 2 = 2  r 0
2   / 2 = 1  r 0
1   / 2 = 0  r 1
---------------
10001100
---------------

Binary to Hexadecimal

Because each hexadecimal digit can be 16 different values, we need 4 binary bits to store it, as 24 = 16 (and log2 16 = 4). So to convert binary to hexadecimal, we group our bits into quartets (fours) and then convert each quartet to its value in hexadecimal.

Below we show this grouping into four to convert 10001100 to hexadecimal, getting the answer 8C

Binary:      1000 1100
Decimal:     8    12
Hexadecimal: 8    C

To go the other way, (i.e. from hexadecimal to binary) follow the process in reverse. Convert each hexadecimal digit into binary, and then concatenate them together.

If we wanted to convert binary to another numerical base that is a power of 2, e.g. 8 or 32, we can group the bits differently, e.g. into 3s or 5s.


Questions

1. Check your understanding

Use pen and paper to convert the following numbers, then check your answers here.

1. Binary To Decimal

Check Answers

2. Hex to decimal

Check Answers

3. Binary to hex

Do not include a prefix or leading zeroes. Enter values in CAPS.

Check Answers

4. Hex to Binary

Do not include a prefix or leading zeroes.

Check Answers

5. Decimal to other bases

Convert the number in decimal to the base shown. Enter letters in CAPS.

Check Answers

5. Binary to other bases

Convert the number from binary straight to the base shown. Enter letters in CAPS.

Check Answers


Summary

In this section we have learned how to convert between different bases.

  • You should be able to convert straight between any of binary, decimal, and hexadecimal.
  • You should be able to convert from decimal to any numerical base.
  • You should be able to convert straight from binary to any power-of-two base.

In the next section we will start looking at how to do binary arithmatic, beginning with addition and subtraction of binary numbers.