[Tutor] Concatenating string

tee chwee liong tcl76 at hotmail.com
Wed Feb 23 15:21:45 CET 2011


> The interesting questions are:
> 1- are you SURE you were using 2.5 yesterday?
> If so:
> 2- did you import some modules? Which ones?
> On my phone I have Python 2.5 too, and it gives the same errors to me.
> 
> Is it possible that you upgrade to 2.6 or 2.7 ?
> 
 
hi,
 
yes i'm sure using Python 2.5 because that's the only version i have. however i was playing around on how to convert hex to bin, can't remember whether imported special module. 
anyway here is the code that converts hex to bin:
import binascii 
def byte_to_binary(n): 
    return ''.join(str((n & (1 << i)) and 1) for i in reversed(range(8)))
def hex_to_binary(h): 
    return ''.join(byte_to_binary(ord(b)) for b in binascii.unhexlify(h))
array0 = '000a00000003c0000030000c1f800000'
a=hex_to_binary(array0)
print "a:",a

thanks
tcl
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110223/2bfa344f/attachment.html>


More information about the Tutor mailing list