Java Integer to Byte Array intToBytes(int i)

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

Description

Spilts an int into 4 bytes

License

Creative Commons License

Parameter

Parameter Description
i Integer to split

Return

4-byte array, 0th byte being the first byte in an integer

Declaration

private static byte[] intToBytes(int i) 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

public class Main {
    /**/*from ww  w.  j  ava2s .  c o m*/
     * Spilts an int into 4 bytes
     * @param i Integer to split
     * @return 4-byte array, 0th byte being the first byte in an integer
     */
    private static byte[] intToBytes(int i) {
        return new byte[] { (byte) (i >> 24), (byte) (i >> 16), (byte) (i >> 8), (byte) i };
    }
}

Related

  1. intToBytes(int a, byte[] b, int bo)
  2. intToBytes(int i)
  3. intToBytes(int i)
  4. intToBytes(int i)
  5. intToBytes(int i)
  6. intToBytes(int i)
  7. intToBytes(int i)
  8. intToBytes(int i)
  9. IntToBytes(int i)