Android Byte Array Reverse reverse(byte[] original)

Here you can find the source of reverse(byte[] original)

Description

reverse

Parameter

Parameter Description
original a parameter

Declaration

public static byte[] reverse(byte[] original) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  ww  w  . j a v a  2  s. c om
     * 
     * @param original
     * @return
     */
    public static byte[] reverse(byte[] original) {
        byte[] result = new byte[original.length];

        final int stop = original.length >> 1;
        byte x, y;

        for (int i = 0; i < stop; i++) {
            x = original[i];
            y = original[original.length - i - 1];

            if (0 != (x ^ y)) {
                x ^= y;
                y ^= x;
                x ^= y;
            }

            result[i] = x;
            result[original.length - i - 1] = y;
        }
        if (1 == original.length % 2) {
            result[stop] = original[stop];
        }

        return result;
    }
}

Related

  1. reverse(byte[] data)
  2. reverseWord(byte[] b)
  3. reverseWordLatin(byte[] b)
  4. reverse(byte[] byteArray)
  5. reverseBytes(byte[] bytes)