转自:C语言中printf直接打出2进制数是%什么?16进制是什么?
1 void print_2(int val2) 2 { 3 unsigned char *p = (unsigned char*)&val2 + 3; //从低位到高位,低端字节计算机 4 for(int k = 0; k <= 3; k++) 5 { 6 int val2 = *(p-k); 7 for (int i = 7; i >= 0; i--) 8 { 9 if(val2 & (1 << i)) 10 printf("1"); 11 else 12 printf("0"); 13 } 14 printf(" "); 15 } 16 }