Java ByteOrder getUnsignedShort(final int offset, final byte[] buffer, final ByteOrder byteOrder)

Here you can find the source of getUnsignedShort(final int offset, final byte[] buffer, final ByteOrder byteOrder)

Description

get Unsigned Short

License

Open Source License

Declaration

public static final int getUnsignedShort(final int offset, final byte[] buffer, final ByteOrder byteOrder) 

Method Source Code


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

import java.nio.ByteOrder;

public class Main {
    public static final int getUnsignedShort(final int offset, final byte[] buffer, final ByteOrder byteOrder) {
        if (byteOrder == ByteOrder.BIG_ENDIAN) {
            return (buffer[offset + 0] & 0xff) << 8 | buffer[offset + 1] & 0xff;
        }//from ww  w. ja v  a2 s. c  o  m

        return (buffer[offset + 1] & 0xff) << 8 | buffer[offset + 0] & 0xff;
    }
}

Related

  1. getByteOrder(final String value)
  2. getInt(byte[] b, int start, int end, ByteOrder byteOrder)
  3. getInt(final int offset, final byte[] buffer, final ByteOrder byteOrder)
  4. getLong(byte[] b, int start, int end, ByteOrder byteOrder)
  5. getMostSignificantByte(byte[] bytes, ByteOrder byteOrder)
  6. increaseNumberOfBytes(byte[] originalBytes, int desiredNumberOfBytes, ByteOrder byteOrder, boolean isSigned)
  7. isNegative(byte[] bytes, ByteOrder byteOrder, boolean isSigned)
  8. longToBytes(long longValue, ByteOrder byteOrder, boolean isSigned)
  9. opposite(ByteOrder order)