16进制转化成10进制代码
时间: 2023-12-20 16:30:09 浏览: 23
以下是VC编程实现16进制浮点数转换为10进制的代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX_LEN 100
int main()
{
char hex[MAX_LEN];
double decimal = 0.0;
int len, i, j, k, exp = 0;
printf("Enter a hexadecimal number: ");
scanf("%s", hex);
len = strlen(hex);
for (i = len - 1; i >= 0; i--)
{
if (hex[i] >= '0' && hex[i] <= '9')
{
decimal += (hex[i] - '0') * pow(16, exp);
}
else if (hex[i] >= 'A' && hex[i] <= 'F')
{
decimal += (hex[i] - 'A' + 10) * pow(16, exp);
}
else if (hex[i] >= 'a' && hex[i] <= 'f')
{
decimal += (hex[i] - 'a' + 10) * pow(16, exp);
}
exp++;
}
printf("The decimal equivalent of %s is %lf\n", hex, decimal);
return 0;
}
```