根据问题
https://stackoverflow.com/questions/1738244/what-is-the-java-equivalent-of-net-bitconverter中提供的建议,我已经开始为Java实现我自己的bitconverter,但是没有得到相同的结果.
有人可以指导我可能做错了吗?
public static byte[] GetBytes(Integer value) {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
DataOutputStream stream = new DataOutputStream(byteStream);
try {
stream.writeInt(value);
} catch (IOException e) {
return new byte[4];
}
return byteStream.toByteArray();
}
byte[] result = BitConverter.GetBytes(1234); //JAVA: [0, 0, 4, -46]
byte[] result = BitConverter.GetBytes(1234); //C#: [210, 4, 0, 0]