I want to perform a conversion without resorting to some implementation-dependent trick. Any tips?
You need to know the endianness of your bytes.
Assuming (like @WhiteFang34) that bytes
is a byte[]
of length 4, then...
Big-endian:
int x = java.nio.ByteBuffer.wrap(bytes).getInt();
Little-endian:
int x = java.nio.ByteBuffer.wrap(bytes).order(java.nio.ByteOrder.LITTLE_ENDIAN).getInt();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With