Here you can find the source of toByteArray(long val, byte[] b, int pos)
public static void toByteArray(long val, byte[] b, int pos)
//package com.java2s; import java.nio.ByteBuffer; import java.nio.FloatBuffer; public class Main { public static void toByteArray(float val, byte[] b, int pos) { try {/* www. ja v a 2s . co m*/ ByteBuffer bb = ByteBuffer.allocate(4); FloatBuffer fb = bb.asFloatBuffer(); fb.put(val); for (int i = 0; i < 4; i++) { b[pos + i] = bb.get(i); } // b = bb.array(); } catch (Exception e) { e.printStackTrace(); } } public static void toByteArray(long val, byte[] b, int pos) { assert (pos + 8 <= b.length); for (int i = 0; i < 8; ++i) { b[pos + i] = (byte) (val & 0x00000000000000FFl); val = val >> 8; } } public static void toByteArray(long val, int w, byte[] b, int pos) { assert (pos + 8 <= b.length); for (int i = 0; i < w; ++i) { b[pos + i] = (byte) (val & 0x00000000000000FFl); val = val >> 8; } } public static void toByteArray(int val, byte[] b, int pos) { assert (pos + 4 <= b.length); for (int i = 0; i < 4; ++i) { b[pos + i] = (byte) (val & 0x000000FF); val = val >> 8; } } public static void toByteArray(short val, byte[] b, int pos) { assert (pos + 2 <= b.length); b[pos] = (byte) (val & 0x00FF); b[pos + 1] = (byte) ((val & 0xFF00) >> 8); } }