0

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!

3
  • try "aa28f5c91a24293a3278".encode() Commented Sep 24, 2021 at 15:16
  • @don'ttalkjustcode i know, it looks the same when it gets printed, sry didn't thought about that Commented Sep 24, 2021 at 15:18
  • 1
    It helps if you can tell us what that string is. There is a good answer assuming that this is a hex encoded string. If that's true, post that info in your question. Commented Sep 24, 2021 at 15:20

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.