Java - Byte Order of a Machine

Introduction

To know the byte order (endian-ness) of your machine, use the nativeOrder() method of the ByteOrder class.

The program prints the byte order of the machine on which it is run.

Demo

import java.nio.ByteOrder;

public class Main {
  public static void main(String args[]) {
    ByteOrder b = ByteOrder.nativeOrder();
    if (b.equals(ByteOrder.BIG_ENDIAN)) {
      System.out.println("Big endian");
    } else {//from w ww  . ja  va  2 s .  c o  m
      System.out.println("Little endian");
    }
  }
}

Result

Related Topic