import binascii bin = lambda n:(n > 0) and (bin(n/2) + str(n%2)) or '' s = 'hello world,this is python' s_16 = binascii.b2a_hex(s) s_10 = int(s_16,16) s_2 = bin(s_10) print s_2 s_10 = int(s_2,2) s_16 = '%x'%(s_10) s = binascii.a2b_hex(s_16) print s
这个只是支持ascii码,不过感觉是个歪解。暂且留此备忘吧~