Here you can find the source of toBytesBigEndian(long value, int sizeInByte)
Parameter | Description |
---|---|
value | int/long value. |
sizeInByte | Size of byte array in byte. |
public static byte[] toBytesBigEndian(long value, int sizeInByte)
//package com.java2s; public class Main { /**/*from w ww . jav a2s .c o m*/ * Convert int/long to n-byte array. * * @param value int/long value. * @param sizeInByte Size of byte array in byte. * @return int/long as big-endian byte array of size {@code sizeInByte}. */ public static byte[] toBytesBigEndian(long value, int sizeInByte) { byte[] out = new byte[sizeInByte]; for (int i = (sizeInByte - 1); i >= 0; i--) { out[i] = (byte) value; value >>>= 8; } return out; } }