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

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -