Java Short to Byte Array fromShort(short input)

Here you can find the source of fromShort(short input)

Description

Returns a byte array containing 2 network byte ordered bytes representing the given short .

License

BSD License

Parameter

Parameter Description
input An short to convert to a byte array.

Return

A byte array representation of an short in network byte order (i.e., big-endian order).

Declaration

public static byte[] fromShort(short input) 

Method Source Code

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

public class Main {
    /**//  w  w w.  java 2  s . c om
     * Returns a byte array containing 2 network byte ordered bytes representing
     * the given {@code short}.
     *
     * @param input An {@code short} to convert to a byte array.
     * @return A byte array representation of an {@code short} in network byte
     * order (i.e., big-endian order).
     */
    public static byte[] fromShort(short input) {
        byte[] output = new byte[2];
        output[0] = (byte) (input >> 8);
        output[1] = (byte) input;
        return output;
    }
}

Related

  1. fromShort(int shortValue)
  2. fromShort(short key)
  3. fromShort(short number)
  4. fromShort(short value)