将str_dec[10] = {11,22,33,44,55}转换成最终数字1122334455
将str_hex[10] = {0x11,0x22,0x33,0x44,0x55}转换成10进制数字
相当于将0x1122334455 装换成10进制数字的效果
代码如下
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int main()
{
int i = 0;
int j = 0;
long dec_value = 0;
long hex_value = 0;
long hex_value_array_value = 0;
long str_dec[10] = {11,22,33,44,55};//用来作参考转换的10进制数字数组
unsigned char str_hex[20] = {0x11,0x22,0x33,0x44,0x55};
long hex_value_array[10] = {0};
for(i = 0; i < 5; i ++)
{
hex_value_array[i] = str_hex[i];
for(j = 4 - i; j > 0; j --)
{
str_dec[i] = str_dec[i]*100;
hex_value_array[i] = hex_value_array[i]*256;
}
dec_value = str_dec[i] + dec_value;
hex_value_array_value = hex_value_array[i] + hex_value_array_value;
hex_value = str_hex[i] + hex_value;
}
printf("dec_value = %ld\n",dec_value);//用来作参考转换的10进制数字结果
printf("hex_value_array_value = %ld\n",hex_value_array_value);
return 0;
}
运行效果下图
dec_value 是10进制算法参考值
![]()
用电脑计算器在hex上输入1122334455
对应的dec 值也是73,588,229,205,证明我的算法是对的

5221

被折叠的 条评论
为什么被折叠?



