Java and C# - byte array to long conversion difference Java and C# - byte array to long conversion difference arrays arrays

Java and C# - byte array to long conversion difference


This is a difference in endianness.

If you reverse the byte array, it works as expected:

BitConverter.ToInt64(new byte[] { 8, 204, 137, 162, 234, 40, 150, 50 }, 0)

You can set the endianness in Java by calling bb.order(ByteOrder.LITTLE_ENDIAN).

By the way, the easiest way to play with these things is to use LINQPad.