Originally Posted by
robatino
I should mention that what I'm thinking of only prints as many digits as it needs - for example, for 2, it would print 10, not 0000000000000010. If you need it to print exactly 16 digits, that would be more difficult, but could probably be done in a similar way. If you need it to print 16 digits in groups of 4, with spaces in between, as you wrote, that's a little tricky. If you know about the correspondence between hexadecimal and binary digits, that helps.
Edit: There's also an ugly solution involving bitwise operators, if you need the answer formatted exactly as you wrote.