1 year ago
#341230
Babushka
Big-endian byte to Int in java
I have this server-client protocol in my project and in the first byte of the message there is the message code (<MsgCode><MsgLength><Msg>).
response += data_length.to_bytes(k_MESSAGE_DATA_LENGTH_BYTES, "big")
response += response_message.encode()
response += '\n'.encode()
client_socket.sendall(response)
(message_code = 202 and k_MESSAGE_CODES_BYTES = 1)
However, at my client (written in Java - for android):
private BufferedReader m_input;
...
String line = m_input.readLine();
int code = line.charAt(0);
The code is - '�' 65533
How can I get the code 202 and not this strange value?
Saw that in Python the response looks like this: b'\xca'
However, couldn't understand why in Java the value is so different. Tried to look up a solution but couldn't find.
python
java
byte
protocols
endianness
0 Answers
Your Answer