Android Byte Array to Int Convert getUIntByByteArray(byte[] data)

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

Description

new byte[] { 8, 4, 2, 1 } => 00000001 00000010 00000100 00001000

License

Open Source License

Parameter

Parameter Description
data a parameter

Declaration

public static long getUIntByByteArray(byte[] data) 

Method Source Code

//package com.java2s;

public class Main {
    public static long getUIntByByteArray(byte[] data, boolean isLH) {

        long result = 0;
        for (int i = 0; i < data.length; i++) {
            byte b = data[i];

            int t = getUIntByByte(b);
            result += t << ((isLH ? i : data.length - i - 1) * 8);
        }/* ww  w . j  a  v a 2 s.  co  m*/

        return result;
    }

    /**
     * new byte[] { 8, 4, 2, 1 } => 00000001 00000010 00000100 00001000
     * 
     * @param data
     * @return
     */
    public static long getUIntByByteArray(byte[] data) {
        return getUIntByByteArray(data, true);
    }

    /**
     * new byte[] { 8, 4, 2, 1 } => 00000001 00000010 00000100 00001000
     * 
     * @param data
     * @return
     */
    public static int getUIntByByte(byte data) {
        return data & 0xFF;
    }
}

Related

  1. getIntFromByteArray(final byte[] bytes)
  2. getIntLE2(byte[] b, int offset)
  3. getInts(int[] toInts, byte[] fromBytes)
  4. getInts(int[] toInts, byte[] fromBytes, int fromOffset)
  5. getUIntByByte(byte data)
  6. getUIntByByteArray(byte[] data, boolean isLH)
  7. toInt(byte[] src)
  8. toInt(byte[] src, int srcPos)
  9. toIntFromTwoBytes(byte[] b, int pos)