F:\Vijay\C> type byte_bits.c
 1
 2  /*
 3   * byte_bits.c  -   Convert a byte into correspondig bit pattern
 4   * Author       -   Vijay Kumar R Zanvar <vijoeyz@hotmail.com>
 5   * Date         -   Mar 21, 2004
 6   */
 7
 8  #include <stdio.h>
 9  #include <stdlib.h>
10  #include <limits.h>
11
12  int
13  main ( void )
14  {
15      unsigned long c = 0xd1; /* short c = .. ; will also work */
16      char bits[sizeof (c)*CHAR_BIT+1] = "";
17      int     i = sizeof c * CHAR_BIT-1,
18              j = 0,
19          times = sizeof c * CHAR_BIT;
20
21      while ( times-- )
22          bits[j++] = ((c >> i--) & 1) + '0';
23
24      printf ( "Bit-representaion of %#lx is %s\n", c, bits );
25      return EXIT_SUCCESS;
26  }
27


F:\Vijay\C> gcc -Wall byte_bits.c
F:\Vijay\C> a.exe
Bit-representaion of 0xd1 is 11010001