user93796 user93796 - 2 years ago 96
Java Question

find endianness of system in java

I found out that algorithm (int C) for checkink if machine is bigindian or littleindian is

int is_big_endian(void)
union {
uint32_t i;
char c[4];
} bint = {0x01020304};

return bint.c[0] == 1;

How can i find such thing in *java?*I dont want to use inbuilt libs as this is a interview question.I want to find it out in java.

Nim Nim
Answer Source

I take no credit for this, however you can try:

import java.nio.ByteOrder;

if (ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN)) {
} else {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download