Java Integer to Byte Array intToByteArray(int value)

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

Description

Convert the specified int to a 4 byte array.

License

Open Source License

Parameter

Parameter Description
value The value

Return

The byte array

Declaration


public static byte[] intToByteArray(int value) 

Method Source Code

//package com.java2s;

public class Main {
    /** Convert the specified int to a 4 byte array.
        /*from ww w.j  a va 2s. c o m*/
    @param value The value
    @return The byte array
    */

    public static byte[] intToByteArray(int value) {
        byte[] b = new byte[4];
        for (int i = 0; i < 4; i++) {
            int offset = (b.length - 1 - i) * 8;
            b[i] = (byte) ((value >>> offset) & 0xFF);
        }
        return b;
    }
}

Related

  1. intToByteArray(int pSrc, byte[] pDst, int pOffset)
  2. intToByteArray(int source)
  3. IntToByteArray(int val, byte[] buf, int offset)
  4. intToByteArray(int value)
  5. intToByteArray(int value)
  6. intToByteArray(int value)
  7. intToByteArray(int value)
  8. intToByteArray(int value)
  9. intToByteArray(int value)