Java Utililty Methods Short Number Create

List of utility methods to do Short Number Create

Description

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

Method

shorttoShort(byte[] bytes)
Convert byte[2] to short
int mask = 0xff;
int temp = 0;
short n = 0;
for (int i = 0; i < 2; i++) {
    n <<= 4;
    temp = bytes[i] & mask;
    n |= temp;
return n;
shorttoShort(byte[] bytes, boolean bigEndian)
Converts a byte array to a signed short value.
if (bytes.length == 1) {
    return bytes[0];
} else if (bigEndian) {
    return (short) ((bytes[0] << 8) | (0xff & bytes[1]));
} else {
    return (short) ((bytes[1] << 8) | (0xff & bytes[0]));
shorttoShort(byte[] bytes, int from)
to Short
short result = 0;
for (int i = 0; i < 2; i++) {
    short b = (short) (((int) bytes[from + i]) & 0xFF);
    result = (short) ((result << 8) | b);
return result;
shorttoShort(byte[] bytes, int offset)
Convert a byte array to a short value
short value = 0;
if (bytes != null && bytes.length >= 2) {
    value += (0x000000FF & bytes[offset]) << 8;
    value += (0x000000FF & bytes[offset + 1]);
return value;
shorttoShort(byte[] bytes, int offset)
to Short
if (offset + SIZEOF_SHORT > bytes.length) {
    throw new RuntimeException("Cannot decode short from the buffer");
short n = 0;
n ^= bytes[offset] & 0xFF;
n <<= 8;
n ^= bytes[offset + 1] & 0xFF;
return n;
...
inttoShort(byte[] data)
Translates a network order byte representation of a short back into a java primitive.
return toShort(data, 0);
shorttoShort(byte[] input)
Converts a given byte array to an short .
assert input.length == 2 : "toShort(): Byte array length must be 2.";
short output = 0;
output = (short) (((input[0] & 0xff) << 8) | (input[1] & 0xff));
return output;
shorttoShort(byte[] key)
to Short
assert (key.length == 2);
int value = ((key[0] << 8) + key[1]);
return ((short) value);
shorttoShort(byte[] readBuffer, int o)
to Short
return (short) (((readBuffer[o + 0] & 255) << 8) + ((readBuffer[o + 1] & 255) << 0));
shorttoShort(byte[] si, boolean isReverseOrder)
Convert a byte[] to the corresponding short value.
short i = 0;
if (isReverseOrder) {
    si = reverseOrder(si, 2);
for (byte b = 0; b <= 1; b++) {
    short j;
    if (si[b] < 0) {
        si[b] = (byte) (si[b] & 0x7f);
...