# C Program to Convert Hexadecimal Number to Decimal Number System

C program to convert hexadecimal number to decimal number system using for loop. Hexadecimal number system is a base 16 number system using digits 0 to 7 and A to F whereas Decimal number system is base 10 number system and using digits from 0 to 9. Given an hexadecimal number as input from user convert it to decimal number.

For Example:

#### Required Knowledge

Algorithm to convert Hexadecimal to Decimal number
• Hexadecimal digits includes characters from A to F corresponding to 10 to 15 respectively. Hence, for hex digit form A to F we will use their decimal equivalent 10 to 15 form any calculation.
• We multiply each digit with 16i and add them, where i is the position of the Hexadecimal digit(starting from 0) from right side. Least significant digit is at position 0.
Decimal number = 1*163 + 2*162 + 10*161 + 13*160 = 4096 + 512 + 160 + 13 = 4781

## C program to convert a hexadecimal number to decimal number

```#include <stdio.h>
#include <math.h>
#include <string.h>

int main() {
long long decimalNumber=0;
char hexDigits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'A', 'B', 'C', 'D', 'E', 'F'};
int i, j, power=0, digit;

/* Converting hexadecimal number to decimal number */
for(i=strlen(hexadecimal)-1; i >= 0; i--) {
/*search currect character in hexDigits array */
for(j=0; j<16; j++){
decimalNumber += j*pow(16, power);
}
}
power++;
}

printf("Decimal Number : %ld", decimalNumber);

return 0;
}
```
Output
```Enter a Hexadecimal Number
```Enter a Hexadecimal Number