Here you can find the source of intToByteArray(int value, byte[] buffer, int offset)
public static void intToByteArray(int value, byte[] buffer, int offset)
//package com.java2s; /*/* w w w. j a v a 2 s. c o m*/ * Copyright 2008 The Portico Project * * This file is part of portico. * * portico is free software; you can redistribute it and/or modify * it under the terms of the Common Developer and Distribution License (CDDL) * as published by Sun Microsystems. For more information see the LICENSE file. * * Use of this software is strictly AT YOUR OWN RISK!!! * If something bad happens you do not have permission to come crying to me. * (that goes for your lawyer as well) * */ public class Main { /** * Convert the provided int into a byte[] for transmission over the network. */ public static byte[] intToByteArray(int value) { return new byte[] { (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) value }; } /** * Convert the provided into into a byte[] and write the values into the given buffer starting * at the provided offset (this will take up 4 bytes!) */ public static void intToByteArray(int value, byte[] buffer, int offset) { buffer[offset] = (byte) (value >>> 24); buffer[offset + 1] = (byte) (value >>> 16); buffer[offset + 2] = (byte) (value >>> 8); buffer[offset + 3] = (byte) (value); } }