我有一个 4 个字符的数组,我需要一个数字中的 ascii 值。
例如数组中是“joh0”
。结果应为十六进制 0x6a726f00 或 int 111617776。
我在函数 ntohl(int x)
中使用它。
最佳答案
从您的描述来看,这听起来像是您想要的(可能交换了索引):
char str[] = "joh0";
uint32_t val = (uint32_t)str[0]
| (uint32_t)str[1] << 8
| (uint32_t)str[2] << 16
| (uint32_t)str[3] << 24;
但我不知道你从哪里得到 106111104048。
关于c - 如何将 char 数组转换为表示其 ascii 值的整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8206012/