gpt4 book ai didi

c - 如何在 C 中将 ASCII 值数组转换为整数

转载 作者:行者123 更新时间:2023-11-30 20:28:38 25 4
gpt4 key购买 nike

我有一个包含 ASCII 字符的数组。假设,Array[4]。其中,Array[0]=0x38,Array[1]=0x30,Array[2]=0x30,Array[4]=0x30 ==>基本上它在不同的字节中存储了值8000。

现在我想从这个数组中提取 8000 到 uint32 Some_Count 变量。有人可以建议我如何提取它吗?最后 Some_Count 应该有 8000。

请提出建议。

最佳答案

#include <stdio.h>
unsigned int main()
{
char Array[4] = {0x38, 0x30, 0x30, 0x30};
unsigned int result = 0, i = 0;
for( i = 0; i< 4; i++)
{
result = result*10 + (Array[i] - '0`');
}
printf("Result = %d\n", result);
return result;
}

关于c - 如何在 C 中将 ASCII 值数组转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60092940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com