Java Short Number Create toShort(byte[] input)

Here you can find the source of toShort(byte[] input)

Description

Converts a given byte array to an short .

License

BSD License

Parameter

Parameter Description
input A network byte-ordered representation of an short .

Return

The short value represented by the input array.

Declaration

public static short toShort(byte[] input) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

public class Main {
    /**//from ww  w .java 2  s .co m
     * Converts a given byte array to an {@code short}. Bytes are expected in
     * network byte
     * order.
     *
     * @param input A network byte-ordered representation of an {@code short}.
     * @return The {@code short} value represented by the input array.
     */
    public static short toShort(byte[] input) {
        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;
    }
}

Related

  1. toShort(byte[] bytes, boolean bigEndian)
  2. toShort(byte[] bytes, int from)
  3. toShort(byte[] bytes, int offset)
  4. toShort(byte[] bytes, int offset)
  5. toShort(byte[] data)
  6. toShort(byte[] key)
  7. toShort(byte[] readBuffer, int o)
  8. toShort(byte[] si, boolean isReverseOrder)
  9. toShort(byte[] src)