Java Array Swap swapInt(byte[] b, int i)

Here you can find the source of swapInt(byte[] b, int i)

Description

swap Int

License

Open Source License

Parameter

Parameter Description
b a parameter
i a parameter

Declaration

public static int swapInt(byte[] b, int i) 

Method Source Code

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

public class Main {
    /**/*from w w w. j ava2s  .  c om*/
     * @param b
     * @param i
     * @return
     */
    public static int swapInt(byte[] b, int i) {
        return Integer.reverseBytes(bytesToInt(b, i));
    }

    private static int bytesToInt(byte[] b, int i) {
        return ((((b[i + 3]) & 0xff) << 0) | (((b[i + 2]) & 0xff) << 8) | (((b[i + 1]) & 0xff) << 16)
                | (((b[i + 0]) & 0xff) << 24));
    }
}

Related

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