Mega Code Archive

 
Categories / C / Code Snippets
 

Display binary representation

#include <stdio.h> #include <conio.h> int main(void) { char ch; int j; printf("Enter a character: "); ch = getche(); printf("\n"); /* display binary representation */ for(j = 128; j > 0; j = j / 2){ if(j & ch) printf("1 "); else printf("0 "); } return 0; }