Java Integer to Byte Array intToBytes(int n)

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

Description

Convert a integer value to bytes

License

Apache License

Parameter

Parameter Description
n the integer value to convert

Return

bytes of then integer value

Declaration

public static byte[] intToBytes(int n) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w  w w. j  a va  2  s. c  o m*/
     * Convert a integer value to bytes
     * 
     * @param n the integer value to convert
     * @return bytes of then integer value
     * @since  1.0
     */
    public static byte[] intToBytes(int n) {
        byte[] b = new byte[4];
        for (int i = 0; i < 4; i++) {
            b[i] = (byte) (n >> (24 - i * 8));
        }
        return b;
    }
}

Related

  1. intToBytes(int i, byte[] data, int[] offset)
  2. intToBytes(int i_)
  3. intToBytes(int intValue)
  4. intToBytes(int ipInt)
  5. intToBytes(int n)
  6. intToBytes(int num, byte[] arr, int pos)
  7. intToBytes(int num, byte[] bytes, int startIndex)
  8. intToBytes(int number, byte[] destination, int destinationIndex)
  9. intToBytes(int v)