Java ByteBuffer to Int readUnsignedInt(ByteBuffer buffer)

Here you can find the source of readUnsignedInt(ByteBuffer buffer)

Description

Read an unsigned integer from the current position in the buffer, incrementing the position by 4 bytes

License

Apache License

Parameter

Parameter Description
buffer The buffer to read from

Return

The integer read, as a long to avoid signedness

Declaration

public static long readUnsignedInt(ByteBuffer buffer) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.ByteBuffer;

public class Main {
    /**/*from   w  ww  .  j  a  v  a  2  s  .c  om*/
     * Read an unsigned integer from the current position in the buffer,
     * incrementing the position by 4 bytes
     *
     * @param buffer The buffer to read from
     * @return The integer read, as a long to avoid signedness
     */
    public static long readUnsignedInt(ByteBuffer buffer) {
        return buffer.getInt() & 0xffffffffL;
    }

    /**
     * Read an unsigned integer from the given position without modifying the buffers
     * position
     *
     * @param buffer the buffer to read from
     * @param index  the index from which to read the integer
     * @return The integer read, as a long to avoid signedness
     */
    public static long readUnsignedInt(ByteBuffer buffer, int index) {
        return buffer.getInt(index) & 0xffffffffL;
    }
}

Related

  1. readInts(final ByteBuffer bb, final int length)
  2. readInts4(final ByteBuffer buffer, final int[] array, final int count)
  3. readUnsigned(ByteBuffer in, int size)
  4. readUnsignedByte(ByteBuffer buffer)
  5. readUnsignedInt(ByteBuffer buf)
  6. readUnsignedInt(ByteBuffer buffer, int index)
  7. readUnsignedInt(ByteBuffer byteBuf)
  8. readUnsignedMedium(ByteBuffer buf)
  9. readUnsignedShort(ByteBuffer bb)