Android Short to Byte Array Convert shortToBytes(short i)

Here you can find the source of shortToBytes(short i)

Description

Returns a byte array containing the bytes of the given short in big endian order.

License

Open Source License

Parameter

Parameter Description
i - The short to convert.

Return

A byte array containing the 2 bytes of the given short in big endian order.

Declaration

public static byte[] shortToBytes(short i) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from   w  w w.  j av a 2 s  .c  om
     * Returns a byte array containing the bytes of the given short in big endian order.
     * 
     * @param i - The short to convert.
     * 
     * @return A byte array containing the 2 bytes of the given short in big endian order.
     */
    public static byte[] shortToBytes(short i) {
        return new byte[] { (byte) (i >> 8), (byte) (i & 0xFF) };
    }
}

Related

  1. shortToBytes(short number)
  2. shortToBytes(short number)
  3. short2ByteArray(short s)
  4. shortToByte(short number)
  5. shortToBytes(short number)
  6. shorts2bytesBE(short[] val)
  7. shorts2bytesLE(short[] val)
  8. getBytes(short data)