0

How do you convert a bitstring (e.g. a string with only 0 and 1) to its value in hex, using Python?

For example if I have the string "1010110010010001" its output in hex would be: 0xAC91.

derHugo
  • 83,094
  • 9
  • 75
  • 115
victor
  • 41
  • 5
  • Possible duplicate of [Python conversion from binary string to hexadecimal](https://stackoverflow.com/questions/2072351/python-conversion-from-binary-string-to-hexadecimal) – KC. Oct 27 '18 at 03:27

1 Answers1

0

Very easily:

>>> hex(int("1010110010010001", 2))
'0xac91'
Arg0s
  • 191
  • 1
  • 2