In the networking universe we use binary, decimal and hexadecimal values. Two good examples where we use hexadecimal values are MAC addresses and IPv6 addresses.

Especially for IPv6 addresses it’s useful to understand how you can calculate from hexadecimal to binary and decimal or the other way around.

In the decimal system we count from 0-10, in the hexadecimal system we count from 0 – F. Here’s an example:

Decimal |
Hexadecimal |

1 | 1 |

2 | 2 |

3 | 3 |

4 | 4 |

5 | 5 |

6 | 6 |

7 | 7 |

8 | 8 |

9 | 9 |

10 | A |

11 | B |

12 | C |

13 | D |

14 | E |

15 | F |

That’s not so bad right? Now if you want to calculate from binary to hexadecimal there’s a trick you need to master. Let’s say you have the decimal number 255 in binary:

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

1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |

If you want to convert this to hexadecimal you need to cut the 8 bits in two parts of 4 bits (4 bits is also known as a **nibble**).

First nibble:

1 | 1 | 1 | 1 |

Second nibble:

1 | 1 | 1 | 1 |

Now convert these nibbles from binary to decimal:

8 | 4 | 2 | 1 |

1 | 1 | 1 | 1 |

Both nibbles look the same: 8 + 4 + 2 + 1 = 15

Now take a look at the decimal-to-hexadecimal chart and you’ll see that 15 in decimal is equal to “F” in hexadecimal.

So the hexadecimal value = FF. Normally you see hexadecimal values written as 0xFF. If you see “0x”then you know it’s a hexadecimal value.

Let’s try another decimal value and calculate it into hexadecimal, for example 118. First we convert 118 to binary:

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

0 | 1 | 1 | 1 | 0 | 1 | 1 | 0 |

64 + 32 + 16 + 4 + 2 = 118

We’ll chop our 8 bits into two nibbles and this is what we get:

First nibble:

0 | 1 | 1 | 1 |

Second nibble:

0 | 1 | 1 | 0 |

Now let’s convert these nibbles from binary to decimal:

8 | 4 | 2 | 1 |

0 | 1 | 1 | 1 |

The first nibble will be 4 + 2 + 1 = 7. The decimal value 7 is the same in hexadecimal.

8 | 4 | 2 | 1 |

0 | 1 | 1 | 0 |

The second nibble will be 4+2 = 6. The decimal value 6 is the same in hexadecimal.

Our hexadecimal value will be 0x76. Let’s try one more!

Let’s say we have the decimal value 206. In binary it looks like this:

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

1 | 1 | 0 | 0 | 1 | 1 | 1 | 0 |

128 + 64 + 8 + 4 + 2 = 206.

We’ll chop our 8 bits into two nibbles and this is what we get:

First nibble:

1 | 1 | 0 | 0 |

Second nibble:

1 | 1 | 1 | 0 |

Now let’s convert these nibbles from binary to decimal:

8 | 4 | 2 | 1 |

1 | 1 | 0 | 0 |

The first nibble will be 8 + 4 = 12. The decimal value 12 is C in hexadecimal.

8 | 4 | 2 | 1 |

0 | 1 | 1 | 0 |

The second nibble will be 8 + 4 + 2 = 14. The decimal value 14 is E in hexadecimal.

Our hexadecimal value will be 0xCE.

I hope these examples have been useful to you. If yes, share it with your friends! If you have any questions feel free to leave a comment in our forum.

How to convert IPV6 to IPV4 address?

Hi Rene , I don’t understand how you convert nibbles binary to decimal,

Chaps,

I’ve been writing out the place value systems for binary, decimal and hexadecimal and have spotted a pattern that I can’t explain.

For instance…

In Binary - 2 ^ 3 = 1000

In Decimal - 10 ^ 3 = 1,000

In Hexadecimal - 16 ^ 3 = 1000

All results are 1000 even though this is expressed in the three different number systems so are different values.

The pattern repeats no matter what the next power of is:

In Binary - 2 ^ 7 = 10000000

In Decimal - 10 ^ 7 = 10,000,000

In Hexadecimal - 16 ^ 7 = 10000000

This is more of an observation that a question I suppose but if

... Continue reading in our forumHi Gareth

I think you meant any number ^0 is always 1, right? Any number ^1 is simply itself. But it is quite interesting, this world of mathematics isn’t it!?!?!

Laz

Yep - any number to the ^0 is 1 - my bad!!!