Here you can find the source of toBytes(int data)
public static byte[] toBytes(int data)
//package com.java2s; //License from project: Apache License public class Main { public static byte[] toBytes(int data) { return new byte[] { (byte) (data >> 24), (byte) (data >> 16), (byte) (data >> 8), (byte) (data) }; }//from w w w. j a va 2 s . c o m public static byte[] toBytes(short data) { return new byte[] { (byte) (data >> 8), (byte) (data) }; } public static byte[] toBytes(long data) { return new byte[] { (byte) (data >> 56), (byte) (data >> 48), (byte) (data >> 40), (byte) (data >> 32), (byte) (data >> 24), (byte) (data >> 16), (byte) (data >> 8), (byte) (data) }; } public static byte[] toBytes(double data) { long l = Double.doubleToRawLongBits(data); return toBytes(l); } }