Here you can find the source of swapEndian(final int i)
Parameter | Description |
---|---|
i | an <code>int</code> value |
int
value, with the endianness swapped.
public static int swapEndian(final int i)
//package com.java2s; public class Main { /**/*from w ww. j a va 2 s . c om*/ * Converts an int from little endian to big endian, or vice versa. * @param i an <code>int</code> value * @return an <code>int</code> value, with the endianness swapped. */ public static int swapEndian(final int i) { return ((i & 0xff) << 24) | ((i & 0xff00) << 8) | ((i >>> 8) & 0xff00) | ((i >>> 24) & 0xff); } /** * Converts an long from little endian to big endian, or vice versa. * @param l a <code>long</code> value * @return a <code>long</code> value, with the endianness swapped. */ public static long swapEndian(final long l) { return ((l & 0xff) << 56) | ((l & 0xff00) << 40) | ((l & 0xff0000) << 24) | ((l & 0xff000000L) << 8) | ((l >>> 8) & 0xff000000L) | ((l >>> 24) & 0xff0000) | ((l >>> 40) & 0xff00) | ((l >>> 56) & 0xff); } }