f=lambda n:n and'1%s'%f(len(bin(n))-3)+bin(n)[3:] for n in 5, 30, 87654321, 0: print('%8d -> %s' % (n, f(n)))
Standard input is empty
5 -> 1110001 30 -> 111100001110 87654321 -> 111110000101001001110010111111110110001 0 -> 0
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!