Skip to main content

Command Palette

Search for a command to run...

Hexadecimal Conversions

Published
3 min read
Hexadecimal Conversions
R

I am a recent graduate at the beginning of my software development career. I enjoy documenting my learnings through my blogs

Hexadecimal is a base 16 number system, it is made up of numbers 0-9 and letters A-F. In this blog post, I will look at converting Hexadecimal to Decimal and Binary numbers.

Hexadecimal to Decimal

Converting a hexadecimal number to a decimal number is similar to converting binary to decimal, but in this case, we use powers of 16 because hexadecimal is a base-16 system. Here are the steps involved:

  1. Identify the Hexadecimal Digits: Begin by identifying each digit in the hexadecimal number. Hexadecimal uses digits from 0 to 9 and letters from A to F, representing values 10 to 15 in decimal.

  2. Convert Hexadecimal Letters to Decimal: If you encounter any letters (A, B, C, D, E, or F) in the hexadecimal number, replace them with their decimal equivalents: A is 10, B is 11, C is 12, D is 13, E is 14, and F is 15.

  3. Calculate Decimal Value for Each Digit: Starting from the rightmost digit and moving to the left, assign an appropriate power of 16 to each digit. The rightmost digit has a power of 0, the next one has a power of 1, the next one has a power of 2, and so on. Multiply each digit by 16 raised to its respective power and sum up these values.

  4. Add Up the Values: Sum up the decimal values obtained for each digit to get the final decimal equivalent.

Examples:

Fractional Hexadecimal to Decimal

To convert this number to a decimal you use 16 to the power of a minus, meaning anything before the decimal point is positive (2^3) and anything after the decimal point is negative (16^-1)

Hexadecimal to Binary

  1. Convert the Hexadecimal value into its equivalent decimal value: In this step, you correctly mention that you need to convert each hexadecimal digit into its decimal equivalent. For example, A would be 10, and D would be 13.

  2. Convert each individual digit from the hexadecimal number into a 4-digit binary number: This step is where the clarification is needed. Instead of converting each individual digit into a 4-digit binary number, you should convert each hexadecimal digit into its 4-bit binary representation. Hexadecimal digits can represent values from 0 to 15, which require 4 bits to represent. Here's how you can do it:

  • 0 in hexadecimal is 0000 in binary.

  • 1 in hexadecimal is 0001 in binary.

  • 2 in hexadecimal is 0010 in binary.

  • ...

  • 9 in hexadecimal is 1001 in binary.

  • A in hexadecimal is 1010 in binary.

  • B in hexadecimal is 1011 in binary.

  • ...

  • F in hexadecimal is 1111 in binary.

  1. Write these binary numbers from start to finish: After converting each hexadecimal digit into its 4-bit binary representation, you should write these binary digits from start to finish. For example, if your hexadecimal number is A9, you would convert 'A' to '1010' and '9' to '1001', and then write them together as '10101001'. So, your first binary digits should match 'A', and the second set should match '9'.
Examples: