Java Utililty Methods ByteBuffer to Int

List of utility methods to do ByteBuffer to Int

Description

The list of methods to do ByteBuffer to Int are organized into topic(s).

Method

intgetUnsignedByte(ByteBuffer bb)
get Unsigned Byte
return bb.get() & 0xFF;
intgetUnsignedByte(ByteBuffer buffer)
Read an unsigned byte from a buffer
int pos = buffer.position();
int rtn = getUnsignedByte(buffer, pos);
buffer.position(pos + 1);
return rtn;
longgetUnsignedInt(ByteBuffer bb)
Get a unsigned int from byte buffer an put the value in a long
if (bb.remaining() >= 4) {
    return ((0x0FF & bb.get()) << 24) + ((0x0FF & bb.get()) << 16) + ((0x0FF & bb.get()) << 8)
            + (0x0FF & bb.get());
} else {
    throw new IndexOutOfBoundsException();
longgetUnsignedInt(ByteBuffer buffer)
Read an unsigned integer from the current position in the buffer, incrementing the position by 4 bytes
return buffer.getInt() & 0xffffffffL;
longgetUnsignedInt(ByteBuffer buffer)
Read an unsigned integer from the current position in the buffer, incrementing the position by 4 bytes
return buffer.getInt() & 0xffffffffL;
intgetUnsignedInt(ByteBuffer buffer)
Reads a big-endian (31-bit) integer from the buffer and advances position.
return (buffer.get() & 0x7F) << 24 | (buffer.get() & 0xFF) << 16 | (buffer.get() & 0xFF) << 8
        | buffer.get() & 0xFF;
intgetUnsignedInt16LSBMSB(ByteBuffer byteBuffer)
get Unsigned Int LSBMSB
byte[] bytes = getBytes(byteBuffer, 2 * NUM_SHORT_BITS);
int value = 0;
for (int i = 0; i < NUM_SHORT_BITS; i++) {
    value += getUnsignedByte(bytes[i]) << (NUM_INTEGER_BITS * i);
return value;
BigIntegergetUnsignedLong(ByteBuffer buf)
get Unsigned Long
byte[] data = new byte[8];
buf.get(data);
return new BigInteger(data);
longgetUnsignedLong(final ByteBuffer src)
Gets an unsigned long at the current position in the buffer.
return (src.getLong() & LONG_FLAG_MASK_LONG);
intgetUnsignedShort(ByteBuffer bb)
Returns an integer.
return (bb.getShort(0) & 0xffff);