Java Utililty Methods Long to Short

List of utility methods to do Long to Short

Description

The list of methods to do Long to Short are organized into topic(s).

Method

shortLong2Short(long i)
Long Short
short o;
try {
    o = new Long(i).shortValue();
} catch (Exception e) {
    o = 0;
return o;
shortlong2short(long l)
Converts a Long value to a Short value.
return (short) ((l << 48) >> 48);
shortlong2short(long l)
longshort
return (short) (int) (l << 48 >> 48);
ShortlongToShort(final long value)
long To Short
return (short) value;
ShortlongToShort(long l)
long To Short
if (l >= Short.MIN_VALUE && l <= Short.MAX_VALUE) {
    return (short) l;
return null;
short[]longToShort(long[] values)
long To Short
if (values == null) {
    return null;
short[] results = new short[values.length];
for (int i = 0; i < values.length; i++) {
    results[i] = (short) values[i];
return results;
...
shortlongToShortBounds(long value)
casts a long to an short, but if the long is outside the short-range, it will mapped to the end of the range
if (value > Short.MAX_VALUE)
    return Short.MAX_VALUE;
else if (value < Short.MIN_VALUE)
    return Short.MIN_VALUE;
else
    return (short) value;
short[]longToShorts(long n)
long To Shorts
return longToShorts(n, new short[4], 0);
short[]longToShorts(long value)
long To Shorts
short[] shorts = new short[4];
shorts[0] = (short) (value >>> 48);
shorts[1] = (short) (value >>> 32);
shorts[2] = (short) (value >>> 16);
shorts[3] = (short) (value >>> 0);
return shorts;