Java ByteOrder get24BitInt(byte b1, byte b2, byte b3, ByteOrder order)

Here you can find the source of get24BitInt(byte b1, byte b2, byte b3, ByteOrder order)

Description

Returns an integer for the given 3 bytes.

License

Open Source License

Parameter

Parameter Description
b1 top byte
b2 mid byte
b3 low byte
order the byte order

Return

int

Declaration

private static final int get24BitInt(byte b1, byte b2, byte b3, ByteOrder order) 

Method Source Code


//package com.java2s;

import java.nio.ByteOrder;

public class Main {
    /**//from   w w  w  . j ava2  s .c o  m
     * Returns an integer for the given 3 bytes.
     * @param b1 top byte
     * @param b2 mid byte
     * @param b3 low byte
     * @param order the byte order
     * @return int
     */
    private static final int get24BitInt(byte b1, byte b2, byte b3, ByteOrder order) {
        if (order == ByteOrder.BIG_ENDIAN) {
            return ((b1 << 16) | ((b2 & 0xFF) << 8) | (b3 & 0xFF));
        } else {
            return ((b3 << 16) | ((b2 & 0xFF) << 8) | (b1 & 0xFF));
        }
    }
}

Related

  1. byteArrayToNumber(byte[] data, int index, int length, ByteOrder byteOrder)
  2. complementingOrder(ByteOrder order)
  3. convertBytesToBigInteger(byte[] bytes, ByteOrder byteOrder, boolean isSigned)
  4. createWord(final ByteOrder aByteOrder, final int aMSB, final int aLSB)
  5. decode(final ByteOrder aExpectedByteOrder, final byte... aBytes)
  6. getByteOrder(final String value)
  7. getInt(byte[] b, int start, int end, ByteOrder byteOrder)
  8. getInt(final int offset, final byte[] buffer, final ByteOrder byteOrder)
  9. getLong(byte[] b, int start, int end, ByteOrder byteOrder)