问题描述
这里是场景-
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main()
{
uint8_t backoff;
char* value = "300000";
backoff=atoi(value);
printf("value = %s\n",value);
printf("backoff value = %d\n",backoff);
return (0);
}
输出为 -
value = 300000
backoff value = 224
有人可以帮助我了解这种转换是如何发生的吗?
解决方法
很简单。 uint8_t 的值为 0 到 255。您至少需要 uint32_t(uint16_t max 65535)。 224 是适合 8 位整数的真实答案的位。