DEV Community

Isaac Ayodeji Ikusika
Isaac Ayodeji Ikusika

Posted on

More on Number Systems: Working with Base Numbers: Part 2

The first part of this topic introduced and took us through number bases and converting them to base 10.
This post will explain what base 16 numbers are and how to convert from base 10 to other numbers.

Hexadecimals
This is base16. It is represented with numbers and alphabets A to F.
Beginners think it is a complex base because of the alphanumeric representation, but it is not, it is just like the other ones. The alphabet is just a way to make the numbers cleaner. They represent numbers 10-15 because 16 is the maximum number in this base.
For example:
9 base 10 is 9 in base 16
4 base 10 is 4 in base 16
10 base 10 is A in base 16
11 is B
15 is F
16 is 10
493 is 1ED
The reason for the inclusion of the alphabets is, HEX numbers get to tens of numbers in base 10. For example, the conversion of 493 gives 1 14 13 which is confusing because everyone would read 11413 at a glance, hence a way to make it clearer for readers: 1 E(14) D(13) i.e. 1ED πŸ˜€.

Colour white in CSS, #fff is a hexadecimal number, which, when converted, gives 4095. Wonder why colour codes are represented this way?

Conversion of decimal numbers to other bases
We learned last week that base 10 numbers are decimals. So let us see how to convert these numbers to other bases.

  • 4 to base 2
  • 11 to base 8
  • 493 to base 16

In the last conversion from other bases to decimal, we used multiplication. Here, we are going to use division.
To convert a decimal number to another base, you keep dividing it by that base until you have 0 left and the remainder is less than that base then you read the remainder from bottom to top.

4 => 4/2 = 2 r 0
2/2 = 1 r 0
1/2 = 0 r 1
our answer is 100.

11 to base 8

11 => 11/8 = 1 r 3
1/8 = 0 r 1
our answer is 13

493 to base 16
493 => 493/16 = 30 r 13
30/16 = 1 r 14
1/16 = 0 r 1
we have 1 14 13, which is 1ED in hexadecimal

To convert from a base other than decimal to another, you need to convert to decimal before you do the final conversion.

You can do these conversions on your calculator, but I like to think it is a good practice to understand how things work under the hood.

Enjoy. πŸš€

Top comments (0)