Python version of binascii.b2a_hex (binary to hex conversion)?
Graham Guttocks
graham_guttocks at yahoo.co.nz
Fri Apr 27 16:55:16 EDT 2001
Barry A. Warsaw" <barry at digicool.com> wrote:
> def unhexlify(s):
> acc = []
> append = acc.append
> # In Python 2.0, we can use the int() built-in
> int16 = string.atoi
> for i in range(0, len(s), 2):
> append(chr(int16(s[i:i+2], 16)))
> return string.join(acc, '')
Greetings Barry,
I don't mean to look a gift horse in the mouth so to speak, but is
there a way to unhexlify using all builtins such as what I've done
with hexlify here?
def hexlify(b):
return "%02x"*len(b) % tuple(map(ord, b))
Regards,
Graham
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/
More information about the Python-list
mailing list