#include <stdio.h> void printBinary(int a){ int len = sizeof(a)*8; int temp; if (a > 0) { printf("0"); }else{ printf("1"); } for (int i = 0; i <= len-2; i++) { temp = a>>(len-2-i)&1; printf("%d",temp); if (0 == (len-2-i)%8) { printf(" "); } } printf("\n");
} int main(){
printBinary(2);//00000000 00000000 00000000 00000010 }
|