Hexadecimal to Decimal in C | Decimal to Hexadecimal in C

Hexadecimal to Decimal in C


Hexadecimal to Decimal

Hexadecimal Number System

Base 16 number system which consists numbers {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f}.

Decimal Number System

Base 10 number system which consists numbers {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.


Hexadecimal Number System 
Decimal Number System 


 

Hexadecimal to Decimal Conversion Procedure

1. Write down the decimal equivalent of hexadecimal.

2. Find the position of every digit. We should count the position from the right direction of the number. And the position count starts from 0.

Example

1caf - position of f = 0, a = 1, c = 2, 1 = 3.

5afb - position of b = 0, f = 1, a = 2, 5 = 3.

3. Multiply every digit with 16 to the power of their corresponding position. (16 position)

4. Finally, calculate the sum of all the multiples.