Java Integer to Byte intToByte(int i)

Here you can find the source of intToByte(int i)

Description

Converts a given integer value to a byte array

License

Open Source License

Parameter

Parameter Description
i Integer value to convert

Return

Byte array

Declaration

public static byte[] intToByte(int i) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*w  ww .j  av a  2 s . c  o  m*/
     * Converts a given integer value to a byte array
     *
     * @param i
     *            Integer value to convert
     * @return Byte array
     */
    public static byte[] intToByte(int i) {
        final byte[] b = new byte[4];
        for (int j = 3; j >= 0; j--) {
            b[j] = (byte) (i & 0xFF);
            i >>= 8;
        }

        return b;
    }
}

Related

  1. intAsByte(int value)
  2. intTo1Byte(int x)
  3. intTo4Byte(int i)
  4. intToByte(byte[] buf, int off, int value)
  5. intToByte(final int i)
  6. intToByte(int i)
  7. IntToByte(int i)
  8. intToByte(int i)
  9. intToByte(int i_Value)