Hexadecimal to Decimal and Decimal to Hexadecimal Conversion

πŸ’‘
Key learnings:
  • Hexadecimal Number System Definition: The hexadecimal number system is defined as a base-16 system using digits 0-9 and letters A-F.
  • Decimal Number System Basics: The decimal system is a base-10 system, using digits 0-9 to represent numbers.
  • Convert Decimal to Hexadecimal: To convert a decimal number to hexadecimal, divide by 16 and use remainders, such as 75/16 = 4 remainder 11, giving 4B.
  • Convert Hexadecimal to Decimal: To convert a hexadecimal number to decimal, multiply each digit by 16 raised to its position’s power, then sum, like 4D2 = 1234.
  • Practical Use in Computing: Understanding how to convert hexadecimal to decimal and vice versa is crucial in fields like programming and web development.

Hexadecimal is a base-16 positional number system. It uses the digits 0 through 9 and the letters A through F. Like the decimal number system, binary number system and octal number system, it assigns a value to each digit according to its position.

People commonly use decimal for everyday quantities, while digital systems represent information with bits. Hexadecimal gives people a shorter way to write long binary patterns.

One hexadecimal digit corresponds to four bits because 16 equals 2 to the power of 4. Two hexadecimal digits can therefore represent one 8-bit byte. Hexadecimal also appears in programming tools, memory addresses and CSS colour notation.

The 16 symbols in the hexadecimal number system are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F. The first ten have their usual decimal values. The letters A through F represent decimal values 10 through 15.

decimal system
In decimal, the number after 9 is written as 10. The digit 1 moves into the tens position and the ones position returns to 0.

The right-hand decimal digit then counts from 0 through 9 again, producing 10 through 19. After 19, the left-hand digit becomes 2 and the right-hand digit repeats the same cycle for 20 through 29.

The decimal number system has ten available digits at each position. A base-16 system needs sixteen distinct symbols at each position.

Hexadecimal reuses 0 through 9 for its first ten digit values. It then uses familiar letters for the six values that remain.

A represents decimal 10, B represents 11, C represents 12, D represents 13, E represents 14 and F represents 15. These sixteen possible digit values define the hexadecimal system.

                
A β‡’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’     
B β‡’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’    
C β‡’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’   
D β‡’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’  
E β‡’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’ 
F β‡’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’β€’

After the single hexadecimal digit F, the next value is written as 10. Hexadecimal 10 equals decimal 16, and hexadecimal 11 equals decimal 17.
The left-hand digit remains 1 while the right-hand digit runs from 0 through F. This produces hexadecimal values 10 through 1F, which equal decimal values 16 through 31.

The sequence is 10 β‡’ 16, 11 β‡’ 17, 12 β‡’ 18, 13 β‡’ 19, 14 β‡’ 20, 15 β‡’ 21, 16 β‡’ 22, 17 β‡’ 23, 18 β‡’ 24, 19 β‡’ 25, 1A β‡’ 26, 1B β‡’ 27, 1C β‡’ 28, 1D β‡’ 29, 1E β‡’ 30 and 1F β‡’ 31. After 1F, the left-hand digit increases to 2 and the right-hand digit runs from 0 through F again.

Decimal to Hexadecimal Conversion

A value does not change when its numeral is rewritten in another base. Just as you can convert decimal numbers to binary or convert decimal numbers to octal numbers, you can convert a decimal integer to hexadecimal.

For a nonnegative decimal integer, divide by 16 repeatedly. Record each remainder, replace remainders from 10 through 15 with A through F, then read the remainders from last to first.

Start with decimal 7510 and divide it by 16.
75/16 = quotient 4, remainder 11
The remainder 11 is hexadecimal B. Because the quotient 4 is less than 16, the calculation stops here.
4B16 = 7510
For a larger example, use decimal 1693.
Start with 169310.
Divide it by 16.
1693/16 = quotient 105, remainder 13 (D)
Divide the quotient by 16 again.
105/16 = quotient 6, remainder 9
The quotient is now less than 16. Read the final quotient and the remainders in reverse order.
169310 = 69D16
This completes the decimal-to-hexadecimal conversion.
A hexadecimal numeral can also be evaluated by multiplying each digit value by its place weight. From right to left, the weights are 160, 161, 162 and higher powers of 16. For example, 4D2 can be expanded as follows:

For decimal 1234, division by 16 gives quotient 77 and remainder 2. Dividing 77 by 16 gives quotient 4 and remainder 13, or D. Reading from the final quotient to the first remainder gives hexadecimal 4D2.

    
For that we divide 1234 by base 16 and we get 77 as the quotient and 2 as the remainder.161234β†’2
Divide again 77 by 16 and we get 4 as the quotient and 13 or D as the remainder.1677β†’ D
  4 

Video presentation of Decimal to Hexadecimal Conversion

 

Hexadecimal to Decimal Conversion

To convert a hexadecimal integer to decimal, multiply each digit value by its power-of-16 place weight, then add the products.

First replace each letter with its decimal digit value: A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15.

For hexadecimal 45B116, start at the rightmost digit with position 0. Increase the position number by one as you move left.
The expanded calculation is:

The result is decimal 17,841.

The rightmost hexadecimal digit is multiplied by 160. The next digit to the left is multiplied by 161, and the following digit is multiplied by 162. Continue with increasing powers of 16 for any remaining digits. Adding the products gives the decimal value. This place-value expansion is the standard method for hexadecimal to decimal conversion.

For hexadecimal 4D2, multiply the rightmost digit 2 by 160, the middle digit D, or 13, by 161 and the leftmost digit 4 by 162. The sum is 2 + 208 + 1,024 = 1,234 in decimal.
Hence,

Want To Learn Faster? πŸŽ“
Get electrical articles delivered to your inbox every week.
No credit card requiredβ€”it’s 100% free.

About Electrical4U

Electrical4U is dedicated to the teaching and sharing of all things related to electrical and electronics engineering.

Leave a Comment