gpt4 book ai didi

c - int16_t 变成 int32_t F 填充

转载 作者:太空宇宙 更新时间:2023-11-04 05:40:30 25 4
gpt4 key购买 nike

我不明白这是为什么

#include <stdio.h>
#include <stdint.h>


typedef int16_t my_type;

my_type value = 0xFC7F;

int main(int argc, const char * argv[])
{
printf("0x%02X\n", value);
printf("Type uses %lu bytes\n", sizeof(my_type));
}

输出这个

0xFFFFFC7F
Type uses 2 bytes
Program ended with exit code: 0

代替

0xFC7F
Type uses 2 bytes
Program ended with exit code: 0

我在 OSX 10.9 上使用 XCode 5

最佳答案

您正在使用用于整数的 printf 格式说明符 X 进行打印。

使用 h length specifier将其显示为短片。

Live demo

关于c - int16_t 变成 int32_t F 填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20294715/

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