#include <stdio.h>
int main(void)
{
short x = 768;
printf("%04x", x);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这打印
0300
Run Code Online (Sandbox Code Playgroud)
但是当我将此输出重定向到名为temp的文件时.然后我xxd临时...
3033 3030
Run Code Online (Sandbox Code Playgroud)
为什么我不能得到xxd temp,打印
0300
Run Code Online (Sandbox Code Playgroud)
我该怎么办?我不能打印出一个char,没有char值为768的ASCII值?
因为程序的输出是字符,而不是真正的二进制数字.
在您的示例中,您看到打印为字符 "0"的内容实际上存储为二进制 0x30.
如果要输出真正的二进制数据,请使用fwrite().