16进制字符数组转换成10进制数字

将str_dec[10] = {11,22,33,44,55}转换成最终数字1122334455

将str_hex[10] = {11,22,33,44,55}转换成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,证明我的算法是对的

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值