Java Short to Byte Array fromShort(int shortValue)

Here you can find the source of fromShort(int shortValue)

Description

Interpret a short as its binary form

License

LGPL

Parameter

Parameter Description
shortValue The short to interpret to binary

Return

The binary

Declaration

public static byte[] fromShort(int shortValue) 

Method Source Code

//package com.java2s;
/*//from w  ww .ja va 2s . co  m
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
 */

public class Main {
    /**
     * Interpret a short as its binary form
     *
     * @param shortValue The short to interpret to binary
     *
     * @return The binary
     */
    public static byte[] fromShort(int shortValue) {
        byte[] bytes = new byte[2];
        bytes[0] = (byte) (shortValue >> 8);
        bytes[1] = (byte) ((shortValue << 8) >> 8);
        return bytes;
    }
}

Related

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