Here you can find the source of int2bytes(int v)
Parameter | Description |
---|---|
v | value. |
public static byte[] int2bytes(int v)
//package com.java2s; //License from project: Apache License public class Main { /**//from ww w . j a v a 2 s .co m * to byte array. * * @param v value. * @return byte[]. */ public static byte[] int2bytes(int v) { byte[] ret = { 0, 0, 0, 0 }; int2bytes(v, ret); return ret; } /** * to byte array. * * @param v value. * @param b byte array. */ public static void int2bytes(int v, byte[] b) { int2bytes(v, b, 0); } /** * to byte array. * * @param v value. * @param b byte array. * @param off array offset. */ public static void int2bytes(int v, byte[] b, int off) { b[off + 3] = (byte) v; b[off + 2] = (byte) (v >>> 8); b[off + 1] = (byte) (v >>> 16); b[off + 0] = (byte) (v >>> 24); } }