/* *将var变量以二进制的形式进行输出, */ void showbits(int var) {//0x01020304 unsigned char *p = (unsigned char *)&var; int i, j; for(j=0; j<4; j++){//小端格式输出0x04030201 unsigned char byte = *p;//*(p+3)大端格式输出0x01020304 for(i=0; i<8; i++){ putchar(byte & 0x80 ? '1' : '0'); byte <<= 1; } putchar(' '); p++;//p-- } puts(""); } int main() { int a = 0x01020304; showbits(a); return 0; }