Java Convert via ByteBuffer toShort(final byte byteValue, final ByteOrder byteOrder)

Here you can find the source of toShort(final byte byteValue, final ByteOrder byteOrder)

Description

to Short

License

Open Source License

Declaration

public static short toShort(final byte byteValue,
            final ByteOrder byteOrder) 

Method Source Code

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

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Main {
    public static short toShort(final byte byteValue) {
        return toShort(byteValue, ByteOrder.LITTLE_ENDIAN);
    }//ww w  . j  a va 2s  . c o m

    public static short toShort(final byte byteValue,
            final ByteOrder byteOrder) {
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(2);
        byteBuffer.order(byteOrder);
        byteBuffer.put(byteValue);
        byteBuffer.put((byte) 0x00);
        byteBuffer.flip();
        return byteBuffer.getShort();
    }
}

Related

  1. toMappedBuffer(File file)
  2. toMappedBuffer(File file, long start, long end)
  3. toMsftBinary(UUID uuid)
  4. toShort(byte firstByte, byte secondByte)
  5. toShort(byte[] bytes, int index)
  6. toShortArray(byte[] arr)
  7. toShortArray(final byte[] byteArray)
  8. toSimpleList(List attrValues)
  9. toString(byte[] buf, int arrayOffset, int origLimit, StringBuilder sb)