我用C写了以下代码
short a = 0xFFFE;
printf("hex = 0x%X, signed short = %d\n", a & 0xFFFF, a);
Output ---> hex = 0xFFFE, signed short = -2
现在使用 ctypes 在 Python 中做同样的事情
from ctypes import *
mc = cdll.msvcrt
a = c_short(0xFFFE)
mc.printf("hex = 0x%X, signed short = %d\n", a, a)
Output ----> hex = 0xFFFE, signed short = 65534
我不确定为什么输出不同?任何想法?