Here you can find the source of toBytes(long number)
public static byte[] toBytes(long number)
//package com.java2s; //License from project: Apache License public class Main { public static byte[] toBytes(long number) { long temp = number; byte[] b = new byte[8]; for (int i = 0; i < b.length; i++) { b[i] = new Long(temp & 0xff).byteValue(); temp = temp >> 8;/* ww w . j a v a2 s . c o m*/ } return b; } public static byte[] toBytes(int number) { int temp = number; byte[] b = new byte[4]; for (int i = 0; i < b.length; i++) { b[i] = new Integer(temp & 0xff).byteValue(); temp = temp >> 8; } return b; } public static byte[] toBytes(short number) { int temp = number; byte[] b = new byte[2]; for (int i = 0; i < b.length; i++) { b[i] = new Integer(temp & 0xff).byteValue(); temp = temp >> 8; } return b; } public static byte[] toBytes(float f) { int fbit = Float.floatToIntBits(f); byte[] b = new byte[4]; for (int i = 0; i < 4; i++) { b[i] = (byte) (fbit >> (24 - i * 8)); } int len = b.length; byte[] dest = new byte[len]; System.arraycopy(b, 0, dest, 0, len); byte temp; for (int i = 0; i < len / 2; ++i) { temp = dest[i]; dest[i] = dest[len - i - 1]; dest[len - i - 1] = temp; } return dest; } public static byte[] toBytes(String str) { return str.getBytes(); } }