Quote Originally Posted by bithub
I think you need to change your mask for that to work Salem. You displaying the least significant bit, but shifting to the left each time (which will shift in 0s).
Well, you'd be wrong in thinking that.

1 << 0 = 1
1 << 1 = 2
1 << 2 = 4
1 << 3 = 8
...and so on...

Thus, the mask slides down one bit at a time until it reaches the end. Salem is rarely wrong. The only problem in the code is a simple typo:
Code:
if ( ( value & mask ) != 0 ) putchar('1'); else putchar('0');  // display a bit
Forgot a semi-colon. Other than that, it works as intended. Try throwing it in a loop, as suggested, to see for yourself. On an aside:
Code:
bytesInInt = sizeof(int) * 8;
This really should be:
Code:
bitsInInt = sizeof(int) * CHAR_BIT;
Which is found in <limits.h>.

Quzah.