Java Integer to Byte Array intToBytes(int n)

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

Description

int To Bytes

License

Open Source License

Declaration

public static byte[] intToBytes(int n) 

Method Source Code

//package com.java2s;

public class Main {
    public static byte[] intToBytes(int n) {
        return intToBytes(n, new byte[4], 0);
    }/*  ww w .  j a v a 2 s . c  o m*/

    public static byte[] intToBytes(int n, byte[] bs, int off) {
        for (int i = 0; i < 4; i++) {
            bs[i + off] = (byte) (n >> 8 * i & 0xFF);
        }

        return bs;
    }
}

Related

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