Converting Between Binary/Denary/Hexadecimal

Part of AS Computer Science, but also IGCSE (maybe GCSE) Computer Science too, in case you're wondering.

Binary to Denary

Binary headers! These are the values of 2 to the xth value. Use as many as are required for your particular binary string.

Suppose we have 00101100. We can simply add the values of the headers that correspond to each 1, as shown below.

128 64 32 16 8 4 2 1
0 0 1 0 1 1 0 0

32 + 8 + 4 = 44

Denary to Binary

This is done through successive division by 2 until we reach 0. Remainders will always be either 1 or 0. Using our denary value from above, 44:

Divisor Dividend Remainder
2 44
2 22 0
2 11 0
2 5 1
2 2 1
2 1 0
0 1

We read the remainders from bottom to the top to get our final value. In this case, we get 101100. This value fits into a 6-bit register, so in order make it fit into an 8-bit register, we will add 2 zeroes to the left of the string, resulting in 00101100.

Binary to Hexadecimal

A table is needed for this. It's large, but you don't need to memorise anything once you understand the pattern that lies within it.

Binary Denary Hexadecimal
0000 0 0
0001 1 1
0010 2 2
0011 3 3
0100 4 4
0101 5 5
0110 6 6
0111 7 7
1000 8 8
1001 9 9
1010 10 A
1011 11 B
1100 12 C
1101 13 D
1110 14 E
1111 15 F

Look at the binary values. See how they increase? Once you see this pattern, you can make this table on the fly.

Herein lies our method of conversion. Say we have a binary value of 00111100. We split this value into groups of 4, in this case 0011 and 1100. Then we find their corresponding values in this table. In this case, we have 3 and C: 3C.

If we find ourselves with a binary value that cannot be split into groups of 4, then we add zeroes, as needed, to make a complete group of 4. For example, if we have a 6-bit value: 010101, then we would split it as such: 0001 and 0101. Remember that we read these values from right to left.

Hexadecimal to Binary

The same operation as above. Split the hexadecimal value into individual parts, and find their corresponding binary values in the table above.

Denary to Hexadecimal

Successive division by 16. Suppose we have a denary value of 130.

Divisor Dividend Remainder
16 130
16 8 2
0 8

This leaves us with a hexadecimal value of 82. If you ever get remainders > 9, translate them into their corresponding letters.

Hexadecimal to Denary

Suppose with have a hexadecimal value of AE6.

\((A \times 256) + (E \times 16) + (6 \times 1)\)

Alternatively,

\((10 \times 256) + (14 \times 16) + (6 \times 1)\)

Then,

\(2560 + 224 + 6 = 2790\)

Essentially, we split the HEX value in to individual values. AE6 becomes A, E, and 6.

Then, we multiple each individual value by its corresponding hexadecimal heading: 16 to the xth power, where x scales with the number of individual values.

After multiplying, we sum them together, and we have our denary value.

Common Patterns

We can notice that conversion from a denary value into another number system follows a similar convention: successive division by the number of values of that number system. Base 16 means division by 16, base 2 means division by 2.

We can also see that conversion to a denary value involves multiplication and addition with the headers of the corresponding number system.

This article was written on 06/09/2023. If you have any thoughts, feel free to send me an email with them. Have a nice day!