Java Integer to Short intToShortBytes(int a)

Here you can find the source of intToShortBytes(int a)

Description

Convert an int value to a 2-byte array.

License

Open Source License

Parameter

Parameter Description
a int value

Return

byte[2] array

Declaration

public static byte[] intToShortBytes(int a) 

Method Source Code

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

public class Main {
    /**/*from  ww  w  .  jav a 2  s .c  o m*/
     * Convert an int value to a 2-byte array.
     * @param a int value
     * @return byte[2] array
     */
    public static byte[] intToShortBytes(int a) {
        byte[] returnByteArray = new byte[2]; //short is 2 bytes
        returnByteArray[0] = (byte) ((a & 0x0000ff00) >> 8);
        returnByteArray[1] = (byte) ((a & 0x000000ff));
        return returnByteArray;
    }
}

Related

  1. convertIntegerToShort(Integer intValue)
  2. intToShort(int i)
  3. intToShort(int[] values)
  4. intToShortArray(final int intValue)
  5. intToShorts(int n)