【发布时间】:2016-02-04 15:57:09
【问题描述】:
我有
sprintf(ascii,"%X",number) // number = 63 is a decimal integer`
char ascii[] = {51, 70, 0, 0, 0, .... } 显示为“3F”
当我有
value = atoi(ascii);
它返回 value = 3 而不是 63。
我想要的是用 sprintf 进行十六进制转换,显示它,然后将表中的值作为十进制保存到另一个变量中。
怎么做?
【问题讨论】:
-
atoi只知道十进制数 - 使用带有基数 16 的strtol或带有%x的sscanf。 -
只做
value = number;怎么样? -
因为,我通过增加或减少值来改变ascii数组的内容,转换为十进制后保存。
标签: c hex printf decimal ascii