Java Integer to Byte Array intToByteArray(int a)

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

Description

int To Byte Array

License

Open Source License

Declaration

public static byte[] intToByteArray(int a) 

Method Source Code

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

public class Main {
    public static byte[] intToByteArray(int a) {
        return new byte[] { (byte) ((a >> 24) & 0xFF),
                (byte) ((a >> 16) & 0xFF), (byte) ((a >> 8) & 0xFF),
                (byte) (a & 0xFF) };
    }//from   www .j  a v  a 2  s.  c om

    public static void intToByteArray(int a, byte[] dest, int offset) {
        dest[offset] = (byte) ((a >> 24) & 0xFF);
        dest[offset + 1] = (byte) ((a >> 16) & 0xFF);
        dest[offset + 2] = (byte) ((a >> 8) & 0xFF);
        dest[offset + 3] = (byte) (a & 0xFF);

    }
}

Related

  1. intToByteArray(final int val, final byte[] buf, final int offset)
  2. intToByteArray(final int value)
  3. intToByteArray(final int x)
  4. intToByteArray(final int x, final byte[] dst, final int offset)
  5. intToByteArray(int a)
  6. intToByteArray(int bytes)
  7. intToByteArray(int data)
  8. intToByteArray(int i)
  9. intToByteArray(int i)