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.
I take no credit for this, however you can try:
import java.nio.ByteOrder;
if (ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN)) {
System.out.println("Big-endian");
} else {
System.out.println("Little-endian");
}
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