Yes: this is possible. It is also one of my favorite interview questions as even though it is not a difficult problem there is the need to balance the data driven portion of the solution against the code driven protion. The 100% code driven and 100% data driven solutions are both possible thought completely unrealistic.
The best solutions I have seen works at the nibble level - you walk through your data one nibble at a time and then use a table to output the binary representation of each nibble.
Displaying an integer in binary format
ChapiNaples
cRz
Using sprintf("%x", ...) will create the number in hexadecimal format: not in binary format.
Joe Duffy
FHJJr
The best solutions I have seen works at the nibble level - you walk through your data one nibble at a time and then use a table to output the binary representation of each nibble.