How do I convert a string of bits to a hex string in Python? -
i have bit-string of 32 characters need represent hexadecimal in python. example, string "10000011101000011010100010010111"
needs output "83a1a897"
.
any suggestions on how best go in python?
to format hexadecimal can use hex function:
>>> hex(int('10000011101000011010100010010111', 2)) 0x83a1a897
or in format requested:
>>> '%08x' % int('10000011101000011010100010010111', 2) 83a1a897
Comments
Post a Comment