Java ByteBuffer to Int getUnsignedShort(ByteBuffer buffer, int offset)

Here you can find the source of getUnsignedShort(ByteBuffer buffer, int offset)

Description

Reads a big-endian unsigned short integer from the buffer at the provided offset.

License

Open Source License

Declaration

static int getUnsignedShort(ByteBuffer buffer, int offset) 

Method Source Code

//package com.java2s;
/*//from  w w  w. j a  va  2 s. co m
 * Copyright (c) 2015 Twitter, Inc. All rights reserved.
 * Licensed under the Apache License v2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * This file is substantially based on work from the Netty project, also
 * released under the above license.
 */

import java.nio.ByteBuffer;

public class Main {
    /**
     * Reads a big-endian unsigned short integer from the buffer at the provided offset.
     */
    static int getUnsignedShort(ByteBuffer buffer, int offset) {
        return (buffer.get(offset) & 0xFF) << 8 | buffer.get(offset + 1)
                & 0xFF;
    }

    /**
     * Reads a big-endian unsigned short integer from the buffer and advances position.
     */
    static int getUnsignedShort(ByteBuffer buffer) {
        return (buffer.get() & 0xFF) << 8 | buffer.get() & 0xFF;
    }
}

Related

  1. getUnsignedShort(ByteBuffer bb)
  2. getUnsignedShort(ByteBuffer bb)
  3. getUnsignedShort(ByteBuffer bb)
  4. getUnsignedShort(ByteBuffer buf)
  5. getUnsignedShort(ByteBuffer buffer)
  6. getUnsignedShort(ByteBuffer bytes)
  7. getUnsignedSmart(ByteBuffer buf)
  8. getUnsignedSmartInt(ByteBuffer buffer)
  9. getUnsignedVarInt(ByteBuffer buffer, int numBytes)