/* -----------------------------------------------------
   demo C program file used in teaching CS255 in class
   ----------------------------------------------------- */

#include <stdio.h>
void printBits(int x, int n);
void printFBits(float x, int n);



   int main( int argc, char* argv[] )
   {

      double r = 3.14;

      { /* Inner scope (a new scope !) */

         int r = 4;                    /* Illegal in Java */

      }
   }













/* ---------------------------------------------------------------- 
   Help functions to print a representation in bits
   ---------------------------------------------------------------- */
void printBits(int x, int n)	// Integer
{
   int i;

   for ( i = n-1; i >= 0; i-- )
      if ( x & (1<<i) )
         printf("1");
      else
         printf("0");
   printf("\n");
}


void printFBits(float x, int n)	// Float
{
   int i;

   int *p = (int *)&x;

   for ( i = n-1; i >= 0; i-- )
      if ( (*p) & (1<<i) )
         printf("1");
      else
         printf("0");
   printf("\n");
}