unsigned short格式化问题,使用%hx 。请参考scanf 说明符文档(见截图)
#include <stdio.h>
int main(int argc, char *argv[])
{
unsigned short a, c, b;
scanf("%hx%hx", &a, &b);
c = a & b;
printf("%hx & %hx = %hx", a, b, c);
return 0;
}
short类型占位符为%hd
scanf("%hd%hd",&a,&b);
编译器的问题吧,我用的vs2019就是正常的。