Here you can find the source of int32toByteArray(int i)
public static byte[] int32toByteArray(int i)
//package com.java2s; /*//w w w . jav a2 s. c o m * Copyright (C) 2016 Miguel Rodriguez Perez <miguel@det.uvigo.gal> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { public static byte[] int32toByteArray(int i) { byte[] output = new byte[4]; output[0] = (byte) ((i & 0xFF000000) >> 24); output[1] = (byte) ((i & 0x00FF0000) >> 16); output[2] = (byte) ((i & 0x0000FF00) >> 8); output[3] = (byte) (i & 0x000000FF); return output; } }