C / C ++:将char中的十六进制值转换为整数 [英] C/C++: Converting hexadecimal value in char to integer
本文介绍了C / C ++:将char中的十六进制值转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将十六进制值存储为字符:
I have hexadecimal values stored as characters:
char A = '0';
char B = '6';
char C = 'E';
...我需要将它们覆盖为整数。我知道 atoi,但这仅适用于十进制编码的char值。有类似的功能吗?
... I need them coverted to integers. I know 'atoi', but this only works for decimal coded char values. Any similar function?
推荐答案
您可以尝试 strtol
。但是 strtol
需要以0结尾的 char *
,因此:
You could try strtol
. But strtol
needs a 0 terminated char *
, so:
long x = strtol((char[]){A, 0}, NULL, 16);
这篇关于C / C ++:将char中的十六进制值转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文