Conversion of Hex decimal to integer value using C language

PHOTO EMBED

Thu Feb 02 2023 06:07:11 GMT+0000 (Coordinated Universal Time)

Saved by @leawoliu

#include<stdio.h>
#include<string.h>
#include<math.h>
int hextodc(char *hex){
   int y = 0;
   int dec = 0;
   int x, i;
   for(i = strlen(hex) - 1 ; i >= 0 ; --i)//{
      if(hex[i]>='0'&&hex[i]<='9'){
         x = hex[i] - '0';
      }
      else{
         x = hex[i] - 'A' + 10;
      }
      dec = dec + x * pow(16 , y);// converting hexadecimal to integer value ++y;
   }
   return dec;
}
int main(){
   char hex[100];
   printf("Enter Hexadecimal: ");
   scanf("%s", hex);
   printf("
Decimal: %d", hextodc(hex));
   return 0;
}
content_copyCOPY

https://www.tutorialspoint.com/conversion-of-hex-decimal-to-integer-value-using-c-language