0

I have an emulator what generate byte code. But I cant convert this byte to readable format like string or int. The emulator language is Korean and the bytes are:

b'P\xaf\x01P\xe5\x01$\x008\x00\r\x00H\x00)\x00P\x00!'

My first question is what is b'P meaning? An the second is how to convert it to string or int?

2
  • Python is trying to be helpful and displays bytes that map to ASCII characters as the characters. P is \x50. print(b'\x50'.decode('ascii')). Commented Oct 12, 2021 at 12:27
  • And to convert the bytes to string you need to know the actual encoding. Commented Oct 12, 2021 at 12:28

1 Answer 1

1

My first question is what is b'P

That simply means that the byte in question can be rendered in whatever your locale is (probably utf8) as 'P', so python is showing you that rather than the raw byte.

How to convert... to int

Something like

[int(x) for x in a]

?

How to convert... to str

In this case you need to know the encoding. It's not utf-8, or utf-16 or utf-32. You'll have to do some digging, but the basic syntax is:

a.decode("encoding")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.