Here you can find the source of toBytes(int value)
public static byte[] toBytes(int value)
//package com.java2s; /******************************************************************************* * Copyright (c) 2013 Shuichi Miura.// www . j av a 2 s. co m * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * Shuichi Miura - initial API and implementation ******************************************************************************/ public class Main { public static byte[] toBytes(int value) { byte[] bs = new byte[4]; bs[3] = (byte) (0x000000ff & (value)); bs[2] = (byte) (0x000000ff & (value >>> 8)); bs[1] = (byte) (0x000000ff & (value >>> 16)); bs[0] = (byte) (0x000000ff & (value >>> 24)); return bs; } public static byte[] toBytes(long value) { byte[] bs = new byte[8]; bs[7] = (byte) (0x000000ff & (value)); bs[6] = (byte) (0x000000ff & (value >>> 8)); bs[5] = (byte) (0x000000ff & (value >>> 16)); bs[4] = (byte) (0x000000ff & (value >>> 24)); bs[3] = (byte) (0x000000ff & (value >>> 32)); bs[2] = (byte) (0x000000ff & (value >>> 40)); bs[1] = (byte) (0x000000ff & (value >>> 48)); bs[0] = (byte) (0x000000ff & (value >>> 56)); return bs; } public static byte[] toBytes(float value) { int bits = Float.floatToIntBits(value); return toBytes(bits); } public static byte[] toBytes(double value) { long bits = Double.doubleToLongBits(value); return toBytes(bits); } }