Bit extension occuring when trying to store a “byte” of information into a %x

末鹿安然 提交于 2019-12-08 05:04:26

Arguments of type char, short, etc get implicitly converted to int when they're passed to variadic functions such as printf.

Thus, a negative value of one of those types will be sign-extended so that it holds the same value of type int; -1 as a char (which is commonly 0xFF as an unsigned char) will be implicitly converted to -1 as an int (which it seems would hold an underlying representation of 0xFFFFFFFF on your system).

Consider casting your argument to unsigned char to mitigate the sign extension you've noticed.

e.g. printf("Byte: %x\n", (unsigned char) ins_set[ins_idx]);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!