/***************************************************************************
(c) Copyright 2002 Jeremy Russell, All Rights Reserved.
http://homepage.mac.com/hteric/Project4.pdf
****************************************************************************
File : bittest.c
Author : Jeremy Russell
Date : November 14, 2002
Description :
***************************************************************************/
#include <stdio.h>
void displayBits( unsigned );
/***************************************************************************
Function : main
Author : Jeremy Russell
Date : November 14, 2002
Description : 'main' of bittest.c.
Arguments : void
Returns : int
Notes :
See Also :
***************************************************************************/
int main()
{
unsigned x;
printf ("Please intput an integer: ");
scanf ("%u", &x);
displayBits( x );
return 0;
}
/***************************************************************************
Function : displayBits
Author : Jeremy Russell
Date : November 14, 2002
Description : Convert an integer into a printed binary value.
Arguments : unsigned
Returns : void
Notes :
See Also :
***************************************************************************/
void displayBits( unsigned value )
{
unsigned c, displayMask = 1 << 31;
printf( "The binary representation of %u is:\n", value );
for ( c = 1; c <= 32; c++)
{
putchar( value & displayMask ? '1' : '0' );
value <<= 1;
if ( c % 8 == 0)
{
putchar( ' ' );
}
}
putchar( '\n' );
}