Java Integer to Byte Array intToByteArray(int input)

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

Description

Utility method for converting a int into a byte[]

License

Open Source License

Parameter

Parameter Description
input The log to convert

Return

a byte[] representation

Declaration

public static byte[] intToByteArray(int input) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from w w  w.j a v a 2  s .c o m*/
     * Utility method for converting a int into a byte[]
     *
     * @param input The log to convert
     * @return a byte[] representation
     */
    public static byte[] intToByteArray(int input) {
        byte[] output = new byte[4];
        intToByteArray(input, output, 0);
        return output;
    }

    /**
     * Utility method for converting a int into a byte[]
     *
     * @param input The log to convert
     * @return a byte[] representation
     */
    public static void intToByteArray(int input, byte[] output, int offset) {
        output[offset + 0] = (byte) (0xFF & (input >> 24));
        output[offset + 1] = (byte) (0xFF & (input >> 16));
        output[offset + 2] = (byte) (0xFF & (input >> 8));
        output[offset + 3] = (byte) (0xFF & input);
    }
}

Related

  1. intToByteArray(int a)
  2. intToByteArray(int bytes)
  3. intToByteArray(int data)
  4. intToByteArray(int i)
  5. intToByteArray(int i)
  6. intToByteArray(int integer)
  7. intToByteArray(int integer)
  8. intToByteArray(int piValueToConvert, boolean pbBigEndian)
  9. intToByteArray(int pSrc, byte[] pDst, int pOffset)