void printBits(int someInt)
{
int counter, mask;
//Loop through the bits 1 by 1, putting out a 1 for every 1 encountered and a 0 for every 1 encountered
for(counter=1, mask=1; counter <= sizeof(int) * CHAR_BIT; counter++, mask*=2)
{
putchar(((someInt & mask)==0) ? '0' : '1');
//Put spaces between every 8 bits
if(counter != 0 && counter % (CHAR_BIT) == 0 && counter <= (sizeof(int) * CHAR_BIT))
putchar(' ');
}
printf("\n\n");
}
Friday Night Open Thread: Motivation
4 hours ago
No comments:
Post a Comment