Display binary representation : Binary Display « Data Type « C / ANSI-C






Display binary representation


#include <stdio.h>
#include <conio.h>

int main(void)
{
  char ch;
  int i;

  printf("Enter a character: ");
  ch = getche();
  printf("\n");

  /* display binary representation */
  for(i = 128; i > 0; i = i / 2){
    if(i & ch) 
        printf("1 ");
    else 
        printf("0 ");
  }
  return 0;
}


           
       








Related examples in the same category