Here you can find the source of intToBytes(int value)
int
into an array of 4 bytes.
Parameter | Description |
---|---|
value | a parameter |
public static byte[] intToBytes(int value)
//package com.java2s; // modify it under the terms of the GNU General Public License public class Main { /**/*from w w w .ja v a 2 s . c om*/ * Converts an <code>int</code> into an array of * 4 bytes. * TODO: add a switch for endianess * @param value * @return */ public static byte[] intToBytes(int value) { byte[] out = new byte[4]; out[0] = (byte) (value >> 0); out[1] = (byte) (value >> 8); out[2] = (byte) (value >> 16); out[3] = (byte) (value >> 24); return out; } }