Java Array Swap swapEndianFormat(byte[] b)

Here you can find the source of swapEndianFormat(byte[] b)

Description

swap Endian Format

License

Apache License

Declaration

public static byte[] swapEndianFormat(byte[] b) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static byte[] swapEndianFormat(byte[] b) {
        byte[] endianSwappedBytes = new byte[b.length];
        for (int i = 0; i < b.length; i++) {
            endianSwappedBytes[i] = swapEndianFormat(b[i]);
        }/*  w ww. ja v a2  s  .c  o m*/
        return endianSwappedBytes;
    }

    private static byte swapEndianFormat(byte b) {
        int converted = 0x00;
        converted ^= (b & 0b1000_0000) >> 7;
        converted ^= (b & 0b0100_0000) >> 5;
        converted ^= (b & 0b0010_0000) >> 3;
        converted ^= (b & 0b0001_0000) >> 1;
        converted ^= (b & 0b0000_1000) << 1;
        converted ^= (b & 0b0000_0100) << 3;
        converted ^= (b & 0b0000_0010) << 5;
        converted ^= (b & 0b0000_0001) << 7;
        return (byte) (converted & 0xFF);
    }
}

Related

  1. swapBytes(byte[] bytes)
  2. swapBytes(byte[] data)
  3. swapBytes(byte[] dataToSwap, int wordByteLength)
  4. swapBytesAt(byte[] bytes, int p1, int p2)
  5. swapElements(final E[] arr, final int idx1, final int idx2)
  6. swapInt(byte[] b, int i)
  7. swapInts(byte b[], int off, int len)
  8. swapNumbers(int i, int j, double[] array)
  9. swapObjects(Object[] array, int a, int b)