简体   繁体   English

python将未知字节转换为字符串

[英]python convert unknown byte to string

I have an emulator what generate byte code.我有一个生成字节码的模拟器。 But I cant convert this byte to readable format like string or int.但我无法将此字节转换为字符串或 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?我的第一个问题是 b' P是什么意思? An the second is how to convert it to string or int?第二个是如何将其转换为字符串或整数?

My first question is what is b'P我的第一个问题是什么是 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.这只是意味着有问题的字节可以在任何您的语言环境(可能是 utf8)中呈现为“P”,因此 python 向您展示的是它而不是原始字节。

How to convert... to int如何将...转换为int

Something like就像是

[int(x) for x in a]

? ?

How to convert... to str如何将...转换为str

In this case you need to know the encoding.在这种情况下,您需要知道编码。 It's not utf-8, or utf-16 or utf-32.它不是 utf-8、utf-16 或 utf-32。 You'll have to do some digging, but the basic syntax is:您必须进行一些挖掘,但基本语法是:

a.decode("encoding")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM