Functionality is already implemented in the API. Wrap the byte array in ByteBuffer and use ByteBuffer.putLong and ByteBuffer.getLong :
import java.nio.*; import java.util.Arrays; public class Test { public static void main(String... args) throws Exception { long[] longArray = { 1234, 2345, 3456 };
Output:
[0, 0, 0, 0, 0, 0, 4, -46, 0, 0, 0, 0, 0, 0, 9, 41, 0, 0, 0, 0, 0, 0, 13, -128] [1234, 2345, 3456]
aioobe May 25 '10 at 14:49 2010-05-25 14:49
source share