Now that we are aware of how binary number system works, we need to have some knowledge about what hexadecimal system (or hex) is. Like decimal system has a total of 10 digits (0 to 9) and binary has just 2 digits (0 & 1) to represent any data, the hexadecimal system, as the name suggests, has 16 digits to represent any data. The set of digits is as follows:
We see that each hexadecimal number consists of 4 bits. Thus, every byte consists of 2 hexadecimal numbers. From the previous article, we know that we wrote 23 in decimal as 00010111 in binary. If we split it into 4 bits each, 0001 & 0111, the same can be written as 17 in hexadecimal. Thus (23)10 = (00010111)2 = (17)16
Since there are 10 digits in a decimal system, the value of each digit increases by a factor of 10 as we go from right to left in a number. Similarly, the value of each digit increases by a factor of 2 in binary number system as we go from right to left in a number. Extending this logic to the hexadecimal system, the value of each digit will increase by a factor of 16 as we go from right to left in a number. The rightmost digit (known as the least significant digit) of a number always has a Place value of 1 (160). Similarly the leftmost digit is known as the most significant bit. As we move left, the value of digits is 16 (161), 256 (162), and so on in a hexadecimal number system. Thus we see, the Place value of a number increases by a factor of 16 for every digit from right to left. The Face Value of a hexadecimal digit will always be a digit between 0 & F. Let us calculate what the value of the hexadecimal number 17 is in decimal.
Thus, 17 in hexadecimal is equivalent to 23 in decimal. This can be represented as (17)16 = (23)10.
Now that we have seen how to convert hexadecimal numbers to decimal numbers, let us see how to convert decimal numbers to hexadecimal. Let us convert 723 in decimal to hexadecimal.
- Dividing 723 by 16, we get quotient as 45, and remainder as 3.
- Dividing 45 by 16, we get quotient as 2, and remainder as 13 (or D as per table above).
- Dividing 2 by 16, we get quotient as 0, and remainder as 2.
Now, if we read the remainders from the bottom to up and write them, we get 2D3, which is equal to the decimal number 723 as we had already calculated earlier. If we convert the hex 2D3 into binary, we get 1011010011, which is again the binary equivalent of 723 as we had calculated earlier.
For Wikipedia entry on Hexadecimal, click here.
For more posts on Computer basics, click here.
For more posts in The Cyber Cops project, click here.