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[] b)
to Short
short value = 0;
for (int x = 0; x < b.length; x++) {
    value |= b[x] & 0xFF;
    if (x != b.length - 1) {
        value <<= 8;
return value;
...
shorttoShort(byte[] b)
Converts a byte array of 1-2 bytes to a short.
if ((b.length < 1) || (b.length > 2)) {
    throw new IllegalArgumentException("Array of size " + b.length + " cannot be converted to short.");
short result = 0;
for (int i = 0; i < b.length; i++) {
    result = (short) (((0xFF & b[i]) << ((b.length - i - 1) * 8)) | result);
return result;
...
shorttoShort(byte[] b, int off, boolean bigEndian)
to Short
if (bigEndian) {
    return (short) (((b[0] & 0xff) << 8) | (b[1] & 0xff));
} else {
    return (short) (((b[1] & 0xff) << 8) | (b[0] & 0xff));
shorttoShort(byte[] b, int offset)
to Short
return (short) (((b[offset] & 0x000000FF) << 8) + ((b[offset + 1] & 0x000000FF)));
shorttoShort(byte[] buf, int pos)
to Short
return (short) (toUnsignedByte(buf, pos) << 8 + toUnsignedByte(buf, pos + 1));
shorttoShort(byte[] byteArray)
to Short
if (byteArray == null || byteArray.length != 2)
    return 0x0;
return (short) ((0xff & byteArray[0]) << 8 | (0xff & byteArray[1]) << 0);
shorttoShort(byte[] bytes)
This method one little-endian represented byte array converts to short.
return (short) (bytes[0] & OP_PATTERN | (bytes[1] & OP_PATTERN) << 8);
shorttoShort(byte[] bytes)
Converts a byte array to a short value
return toShort(bytes, 0);
shorttoShort(byte[] bytes)
Convert a byte array to a short integer.
return toShort(bytes, true);
shorttoShort(byte[] bytes)
Converts a byte array to a short value
return toShort(bytes, 0, SIZEOF_SHORT);