Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

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

public class Main {
    public static Short byteArrayToShortLE(byte[] bytes) {
        if (bytes.length != (Short.SIZE / Byte.SIZE)) {
            throw new IllegalArgumentException("Incorrect array size to convert to a short");
        }
        ByteBuffer buffer = ByteBuffer.wrap(bytes);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        return buffer.getShort();
    }
}