-1

i need to conver strings like that "aa28f5c91a24293a3278" to get result in bytes, like that "b'\xaa(\xf5\xc9\x1a$):2x'" How to do that in python? thanks!

fenix777
  • 19
  • 3

1 Answers1

2

With bytes.fromhex(my_hex_string):

>>> s = "aa28f5c91a24293a3278"
>>> bytes.fromhex(s)
b'\xaa(\xf5\xc9\x1a$):2x'

This bytes class method returns a bytes object, decoding the given string object. The string must contain two hexadecimal digits per byte, with ASCII whitespace being ignored.

Brad Solomon
  • 38,521
  • 31
  • 149
  • 235