Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static final int ZERO = 0;
    public static final int ONE = 1;
    public static final short MAX_BYTE = 0xff;

    public static short bytesToShort(byte[] bytes) {
        return (short) ((bytes[ONE] & MAX_BYTE) | (bytes[ZERO] & MAX_BYTE) << Byte.SIZE);
    }

    public static short bytesToShort(byte[] bytes, int offset) {
        return (short) ((bytes[offset + ONE] & MAX_BYTE) | (bytes[offset] & MAX_BYTE) << Byte.SIZE);
    }
}