[Tutor] Hex to Str - still an open issue

Alan Gauld alan.gauld at freenet.co.uk
Fri Feb 4 19:51:58 CET 2005

> Does anybody know how to convert a HEX into a BINARY?

The easiest way I know is to use a lookup table on 
the octal representation.

def bin(n):
   bins = ['000','001','010,'011',....'111']
   result = ''   
   for c in oct(n):
     result += bins[int(c,8)]
   return result


Alan G
Author of the Learn to Program web tutor

More information about the Tutor mailing list