Deal With Big-endian And Little-endian Order

Published on: July 3, 1999
Last Updated: July 3, 1999

JAVA virtual machine always used big-endian, Intel x86 used little-endian.

 public class Swab {
   public final static int swabInt(int v) {
     return  (v >>> 24) | (v << 24) | 
       ((v << 8) & 0x00FF0000) | ((v >> 8) & 0x0000FF00);

   public static void main(String argv[]) {
     //  before 0x01020304
     //    after  0x04030201
     int v = 0x01020304;
     System.out.println("before : 0x" + Integer.toString(v,16));
     System.out.println("after  : 0x" + Integer.toString(swabInt(v),16));

Posted On: 3-Jul-1999

Stay on top of the latest technology trends — delivered directly to your inbox, free!

Subscription Form Posts

Don't worry, we don't spam

Written by Bobby

Bobby Lawson is a seasoned technology writer with over a decade of experience in the industry. He has written extensively on topics such as cybersecurity, cloud computing, and data analytics. His articles have been featured in several prominent publications, and he is known for his ability to distill complex technical concepts into easily digestible content.
Latest Stories

Secure your digital life with NordVPN