Java Integer to Byte Array integerToByteArray(int a, byte[] buf)

Here you can find the source of integerToByteArray(int a, byte[] buf)

Description

Converts an integer to a byte array with a length of 4.

License

Apache License

Parameter

Parameter Description
a - The integer to convert.
buf - The byte array to store the integer in. This must be a length of at least 4.

Declaration

public static void integerToByteArray(int a, byte[] buf) 

Method Source Code

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

public class Main {
    /**//ww  w . java2 s  .  c  o  m
     * Converts an integer to a byte array with a length of 4.
     * @param a - The integer to convert.
     * @param buf - The byte array to store the integer in. This must be a length of at least 4.
     */
    public static void integerToByteArray(int a, byte[] buf) {
        buf[0] = (byte) ((a >> 24) & 0xFF);
        buf[1] = (byte) ((a >> 16) & 0xFF);
        buf[2] = (byte) ((a >> 8) & 0xFF);
        buf[3] = (byte) (a & 0xFF);
    }
}

Related

  1. int32ToByteArray(int a)
  2. int32toByteArray(int i)
  3. int32ToByteArray(int integer)
  4. int32ToByteArray(int value)
  5. integerToByteArray(final int integerToSerialize, final byte[] byteArray, final int offset)
  6. integerToByteArray(int value)
  7. IntegerToBytes(int i, byte[] dst, int offset)
  8. integerToBytes(int v, byte[] b)
  9. integerToBytes(int v, byte[] b)