Java Integer to Byte Array intToBytes(int value)

Here you can find the source of intToBytes(int value)

Description

Converting int to bytes

License

Open Source License

Parameter

Parameter Description
value source integer

Return

bytes of integer

Declaration

public static byte[] intToBytes(int value) 

Method Source Code

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

public class Main {
    /**//from w  ww . j  a  v a 2s .  c o m
     * Converting int to bytes
     *
     * @param value source integer
     * @return bytes of integer
     */
    public static byte[] intToBytes(int value) {
        return new byte[] { (byte) (value & 0xFF), (byte) ((value >> 8) & 0xFF), (byte) ((value >> 16) & 0xFF),
                (byte) ((value >> 24) & 0xFF) };
    }
}

Related

  1. intToBytes(int v, final byte[] arr)
  2. intToBytes(int val)
  3. intToBytes(int val, byte[] bytes, int start)
  4. intToBytes(int val, int byteCount)
  5. intToBytes(int value)
  6. intToBytes(int value)
  7. intToBytes(int value, byte[] array, int offset)
  8. intToBytes(int value, byte[] buffer, int offset)
  9. intToBytes(int value, byte[] buffer, int offset, int length, boolean littleEndian)