Java Endian Flip flipEndian(byte[] data)

Here you can find the source of flipEndian(byte[] data)

Description

Reverse the endian-ness of a byte array.

License

Open Source License

Parameter

Parameter Description
data Byte array to flip

Return

Flipped array

Declaration

public static byte[] flipEndian(byte[] data) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   w w  w . j  ava2s  .  c om*/
     * Reverse the endian-ness of a byte array.
     *
     * @param data Byte array to flip
     * @return Flipped array
     */
    public static byte[] flipEndian(byte[] data) {
        if (data == null) {
            return new byte[0];
        }
        byte[] newData = new byte[data.length];
        for (int i = 0; i < data.length; i++) {
            newData[data.length - i - 1] = data[i];
        }

        return newData;
    }
}

Related

  1. flipEndian(byte[] input, int offset, int len, int bits, int scanLineStride, boolean bigEndian)
  2. flipEndian(byte[] original, byte[] output)