Java Endian Flip flipEndian(byte[] original, byte[] output)

Here you can find the source of flipEndian(byte[] original, byte[] output)

Description

Reverse the order of a byte array and write that reordered array to the given output.

License

Open Source License

Parameter

Parameter Description
original input array to reverse (does not get changed)
output output array for results of byte order reversal.

Declaration

public static final void flipEndian(byte[] original, byte[] output) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * SimpleWAVIO - A straightforward library for loading and saving .WAV (RIFF) files as numerical arrays.
 * Copyright (C) 2012,2013  Chuck Ritola
 * // www .  j  av  a  2s  .co  m
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

public class Main {
    /**
     * Reverse the order of a byte array and write that reordered array to the given output. Intra-byte bit order is unchanged.
     * @param original   input array to reverse (does not get changed)
     * @param output   output array for results of byte order reversal.
     * @since Jul 14, 2012
     */
    public static final void flipEndian(byte[] original, byte[] output) {
        for (int i = 0; i < original.length; i++) {
            output[(original.length - 1) - i] = original[i];
        }
    }
}

Related

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