Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    private final static int MAX_UNSIGNED_SHORT_VALUE = 65536;

    public static short uintToShort(int value) {
        if (value <= MAX_UNSIGNED_SHORT_VALUE) {
            if (value >= MAX_UNSIGNED_SHORT_VALUE / 2) {
                return (short) (~(MAX_UNSIGNED_SHORT_VALUE - value) + 1);
            } else {
                return (short) value;
            }
        } else {
            throw new IllegalArgumentException("Value out of range for a short");
        }
    }
}