69,373
社区成员
发帖
与我相关
我的任务
分享
十六进制的不能用atoi();
使用sscanf();
如:
char test[10]="0x0021C0";怎么转换成long l_test,结果是 8640.
sscanf(test, "%X", &l_test);
怎么将8640转换回到 0x0021C0呢?
sprintf(test, "%#X", l_test); //test = "0X21C0"
int main(int argc, char *argv[])
{
long l_test;
char test[10]="0x0021C0";
sscanf(test,"%X", &l_test);
printf("string = %s integer = %d\n", test, l_test);
test[0] = '\0';
sprintf(test,"0x00%X", l_test); //test = "0x0021C0";
printf("string = %s integer = %d\n", test, l_test);
system("PAUSE");
return 0;
}