[英]What encoding is this '\x00\x00\x00\x05'?
I'm sending an Integer from my Java Client to my Python Server using: 我正在使用以下命令从我的Java客户端向我的Python服务器发送一个Integer:
outputStream.writeInt(5);
And on the server: 并在服务器上:
_id = self.request.recv(4)
I get: 我明白了:
Name | Type| Value
_id | str | '\x00\x00\x00\x05'
How can i decode this and convert it back to Integer ? 我该如何解码并将其转换回Integer?
You can decode this with the python struct
module : 您可以使用python
struct
模块对此进行解码:
>>> import struct
>>> struct.unpack('>i', '\x00\x00\x00\x05')
(5,)
The >i
pattern expects a big-endian signed integer (4 bytes). >i
模式需要一个big-endian有符号整数(4个字节)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.