Java Byte Array to Int bytesToInt(final byte[] arr)

Here you can find the source of bytesToInt(final byte[] arr)

Description

Returns an int extracted from a Little-Endian byte array.

License

Apache License

Parameter

Parameter Description
arr the given byte array

Return

an int extracted from a Little-Endian byte array.

Declaration

public static int bytesToInt(final byte[] arr) 

Method Source Code

//package com.java2s;
/*/*from   w w  w  . j av a  2  s.c om*/
 * Copyright 2015-16, Yahoo! Inc.
 * Licensed under the terms of the Apache License 2.0. See LICENSE file at the project root for terms.
 */

public class Main {
    /**
     * Returns an int extracted from a Little-Endian byte array.
     * @param arr the given byte array
     * @return an int extracted from a Little-Endian byte array.
     */
    public static int bytesToInt(final byte[] arr) {
        int v = 0;
        for (int i = 0; i < 4; i++) {
            v |= (arr[i] & 0XFF) << i * 8;
        }
        return v;
    }
}

Related

  1. bytesToInt(byte[] bytesSource)
  2. bytesToInt(byte[] data)
  3. bytesToInt(byte[] data)
  4. bytesToInt(byte[] data)
  5. bytesToInt(byte[] value)
  6. bytesToInt(final byte[] b)
  7. bytesToInt(final byte[] buf, final int offset)
  8. bytesToInt(final byte[] bytes)
  9. bytesToInt(final byte[] bytes)