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

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

Description

get U Int By Byte Array

License

Open Source License

Declaration

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

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);
        }/*  w  w  w . j  av a  2 s  . c  om*/

        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. getIntLE2(byte[] b, int offset)
  2. getInts(int[] toInts, byte[] fromBytes)
  3. getInts(int[] toInts, byte[] fromBytes, int fromOffset)
  4. getUIntByByte(byte data)
  5. getUIntByByteArray(byte[] data)
  6. toInt(byte[] src)
  7. toInt(byte[] src, int srcPos)
  8. toIntFromTwoBytes(byte[] b, int pos)
  9. toInteger(byte[] b, int pos)