马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
char final_1[100];
int q = 0;
int exchage2(char ch)
{
int h=0;
switch (ch)
{
case '0':
h = 0; break;
case '1':
h = 1; break;
case '2':
h = 2; break;
case '3':
h = 3; break;
case '4':
h = 4; break;
case '5':
h = 5; break;
case '6':
h = 6; break;
case '7':
h= 7; break;
case '8':
h = 8; break;
case '9':
h = 9; break;
case'A':
h = 10; break;
case'B':
h = 11; break;
case'C':
h = 12; break;
case'D':
h = 13; break;
case'E':
h = 14; break;
case'F':
h = 15; break;
}
return h;
}
void delesomething(char arr[])
{
for (int i = 0; i < strlen(arr); i++)
{
if (arr[i] <= '9' && arr[i]>='0')
final_1[q++] = arr[i];
else if (arr[i] >= 'A' && arr[i] <= 'F')
{
final_1[q++] = arr[i];
}
else if (arr[i] >= 'a' && arr[i] <= 'f')
{
final_1[q++] = arr[i] + 'A' - 'a';
}
}
}
int exchange(char arr[])
{
long long unsigned sum = 0;
for (int i = strlen(arr) - 1; i >= 0; i--)
{
int b = strlen(arr) - i - 1;
sum += exchage2(arr[i])*pow(16,b);
}
return sum;
}
int main()
{
char arr[100];
gets(arr);
delesomething(arr);
printf("十六进制0x%s\n", final_1);
long long unsigned ar=exchange(final_1);
printf("十进制%lld\n", ar);
return 0;
}
在数比较小的时候转换成功,数比较大就不成功了
本帖最后由 jhq999 于 2021-11-18 20:04 编辑
把int类型的变量和函数类型都换成unsigned long long类型;
printf("十进制%llu\n", ar);
|