Java Long to Byte Array longToByteArray(final long value, final int size)

Here you can find the source of longToByteArray(final long value, final int size)

Description

Classname / Method Name : CalculationHelper/longToByteArray()

License

Apache License

Parameter

Parameter Description
value a parameter
size a parameter

Declaration

public static byte[] longToByteArray(final long value, final int size) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//  w ww .  jav a  2 s. co m
     * 
     * Classname / Method Name : CalculationHelper/longToByteArray()
     * 
     * @param value
     * @param size
     * @return
     * @Description : Method is used to convert long to byte array
     */
    public static byte[] longToByteArray(final long value, final int size) {

        final byte[] b = new byte[size];
        for (int i = 0; i < size; i++) {
            final int offset = (b.length - 1 - i) * 8;
            b[i] = (byte) ((value >> offset) & 0xFF);
        }
        return b;
    }
}

Related

  1. long2bytesBE(long val, byte[] b, int off)
  2. longToByteArr(long v)
  3. longToByteArray(final long l)
  4. longToByteArray(final long v, final byte[] buf, final int offset)
  5. longToByteArray(final long val, final byte[] buf, final int offset)
  6. longToByteArray(long a, byte[] buf)
  7. longToByteArray(long i64)
  8. longToByteArray(long in)
  9. longToByteArray(long input)