Function displaying bits...
Hi,
Since C has no standard way to display the bits of a number, my book has the following function:
Code:
void displayBits( unsigned value )
{
unsigned c, displayMask = 1 << 31;
printf( "%7u = ", value );
for ( c = 1; c <= 32; c++ ) {
putchar( value & displayMask ? '1' : '0' );
value <<= 1;
if ( c % 8 == 0 )
putchar( ' ' );
}
putchar( '\n' );
}
WHat i don't understand is that why it has to use the AND operator, why is the mask needed and why does it need to be
1 << 31, can it be anything else?
thnx