Mega Code Archive

 
Categories / C / Code Snippets
 

Reverse bit pattern

#include <stdio.h> #include <conio.h> int main(void) { char ch; int j; ch = 'd'; /* display binary representation */ for( j = 128; j > 0; j = j / 2) if(j & ch) printf("1 "); else printf("0 "); /* reverse bit pattern */ ch = ~ch; printf("\n"); /* display binary representation */ for( j = 128; j > 0; j = j / 2 ) if(j & ch) printf("1 "); else printf("0 "); return 0; }