19 January 2012

Python hex -> int -> str

import binascii

x=11
print x        #>>  11
print int(x)    #>>  11
print hex(x)      #>> 0xb
print str(x)    #>>  11

x="11"
print x        #>>  11
print int(x)    #>>  11
print hex(x)      #>> ERROR
print str(x)    #>>  11

x=0x11
print x           #>> 17
print int(x)     #>> 17
print hex(x)      #>> 0x11
print str(x)      #>> 17

x = "0x17"
print x        #>> 0x17
print int(x)     #>> ERROR
print hex(x)   #>> ERROR  hex(int)
print str(x)    #>> "0x17"

x="11"
print int(x)        #>>        11
print int(x,2)        #>>        3
print int(x,8)        #>>        9
print int(x,10)    #>>        11
print int(x,16)    #>>        17

x=11
print int(x)        #>>        11
print int(x,2)        #>>  ERROR
print int(x,8)        #>>  ERROR
print int(x,10)    #>>  ERROR
print int(x,16)    #>>  ERROR

x="48454c4C61"
print binascii.unhexlify(x)  #>>    HELLa

x='a'
print ord(x)        #>> 97
print hex(ord(x))    #>> 0x61

No comments:

Post a Comment

Terima kasih