Java ByteOrder getInt(final int offset, final byte[] buffer, final ByteOrder byteOrder)

Here you can find the source of getInt(final int offset, final byte[] buffer, final ByteOrder byteOrder)

Description

get Int

License

Open Source License

Declaration

public static final int getInt(final int offset, final byte[] buffer, final ByteOrder byteOrder) 

Method Source Code


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

import java.nio.ByteOrder;

public class Main {
    public static final int getInt(final int offset, final byte[] buffer, final ByteOrder byteOrder) {
        return (int) getUnsignedInt(offset, buffer, byteOrder);

    }//from  ww w . j  a va2  s . c  om

    public static final long getUnsignedInt(final int offset, final byte[] buffer, final ByteOrder byteOrder) {
        if (byteOrder == ByteOrder.BIG_ENDIAN) {
            return (buffer[offset + 0] & 0xff) << 24 | (buffer[offset + 1] & 0xff) << 16
                    | (buffer[offset + 2] & 0xff) << 8 | buffer[offset + 3] & 0xff;
        }

        return (buffer[offset + 3] & 0xff) << 24 | (buffer[offset + 2] & 0xff) << 16
                | (buffer[offset + 1] & 0xff) << 8 | buffer[offset + 0] & 0xff;
    }
}

Related

  1. createWord(final ByteOrder aByteOrder, final int aMSB, final int aLSB)
  2. decode(final ByteOrder aExpectedByteOrder, final byte... aBytes)
  3. get24BitInt(byte b1, byte b2, byte b3, ByteOrder order)
  4. getByteOrder(final String value)
  5. getInt(byte[] b, int start, int end, ByteOrder byteOrder)
  6. getLong(byte[] b, int start, int end, ByteOrder byteOrder)
  7. getMostSignificantByte(byte[] bytes, ByteOrder byteOrder)
  8. getUnsignedShort(final int offset, final byte[] buffer, final ByteOrder byteOrder)
  9. increaseNumberOfBytes(byte[] originalBytes, int desiredNumberOfBytes, ByteOrder byteOrder, boolean isSigned)