Java ByteBuffer to Int getUShort(ByteBuffer buffer)

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

Description

get U Short

License

Open Source License

Declaration

public static int getUShort(ByteBuffer buffer) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    public static int getUShort(ByteBuffer buffer) {

        assert (buffer.capacity() - buffer.position() >= 2);

        byte[] data = new byte[2];

        data[1] = buffer.get();//from w  w  w. j a va  2  s .co m
        data[0] = buffer.get();

        return ((data[0] << 8) & 0x0000ff00) | (data[1] & 0x000000ff);
    }
}

Related

  1. getUnsignedShort(ByteBuffer buffer, int offset)
  2. getUnsignedShort(ByteBuffer bytes)
  3. getUnsignedSmart(ByteBuffer buf)
  4. getUnsignedSmartInt(ByteBuffer buffer)
  5. getUnsignedVarInt(ByteBuffer buffer, int numBytes)
  6. getUShort(ByteBuffer buffer)
  7. getUShort(java.nio.ByteBuffer buffer)
  8. readInt(ByteBuffer buf)
  9. readInt(ByteBuffer buf, int length)