Here you can find the source of longTo4LengthBytes(long num)
public static byte[] longTo4LengthBytes(long num)
//package com.java2s; /*/* w w w . j a v a 2s . com*/ * @(#)ByteConvertUtil.java V0.0.1 2015-2-3, ????1:37:07 * * Copyright 2015 www.ifood517.com. All rights reserved. * www.ifood517.com PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ public class Main { public static byte[] longTo4LengthBytes(long num) { int i = (int) (num); return intToBytes(i); } public static byte[] longTo4LengthBytes(long num, byte[] data, int index) { int i = (int) (num); return intToBytes(i, data, index); } public static byte[] intToBytes(int i) { byte[] intBytes = new byte[4]; intBytes[0] = (byte) (i >> 24); intBytes[1] = (byte) (i >> 16); intBytes[2] = (byte) (i >> 8); intBytes[3] = (byte) (i >> 0); return intBytes; } public static byte[] intToBytes(int i, byte[] data, int index) { data[index] = (byte) (i >> 24); data[index + 1] = (byte) (i >> 16); data[index + 2] = (byte) (i >> 8); data[index + 3] = (byte) (i >> 0); return data; } }