Java Byte Array to Endian bytesToIntLE(byte[] bytes, int offset, int length)

Here you can find the source of bytesToIntLE(byte[] bytes, int offset, int length)

Description

Converts a little-endian sequence of bytes to an int .

License

Open Source License

Parameter

Parameter Description
bytes the byte sequence that is to be converted.
offset the offset to bytes at which the sequence starts.
length the length of the byte sequence.

Return

the int that results from the conversion of the byte sequence.

Declaration


private static int bytesToIntLE(byte[] bytes, int offset, int length) 

Method Source Code

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

public class Main {
    /**//from   w  w  w .ja v a2 s.com
     * Converts a little-endian sequence of bytes to an {@code int}.
     *
     * @param  bytes   the byte sequence that is to be converted.
     * @param  offset  the offset to {@code bytes} at which the sequence starts.
     * @param  length  the length of the byte sequence.
     * @return the {@code int} that results from the conversion of the byte sequence.
     * @since  1.0
     * @see    #bytesToIntBE(byte[], int, int)
     * @see    #intToBytesLE(int, byte[], int, int)
     */

    private static int bytesToIntLE(byte[] bytes, int offset, int length) {
        int i = offset + length;
        int value = bytes[--i];
        while (--i >= offset) {
            value <<= 8;
            value |= bytes[i] & 0xFF;
        }
        return value;
    }
}

Related

  1. BytesToDouble_With_Little_Endian(byte[] bytes)
  2. bytesToInt(byte[] bytes, int offset, int length, boolean littleEndian)
  3. bytesToInt32(byte[] buffer, int byteOffset, boolean bigEndian)
  4. bytesToIntBigEndian(byte[] buf)
  5. bytesToLongLittleEndian(final byte[] vals, final int from)
  6. bytesToNumberLittleEndian(byte[] buffer, int start, int length)
  7. bytesToTag(byte[] bytes, int off, boolean bigEndian)
  8. bytesToXBigEndian(byte[] in, int offset, int size)