Android Long to Byte Array Convert getByteArrayByLong(long value, int n, boolean isLH)

Here you can find the source of getByteArrayByLong(long value, int n, boolean isLH)

Description

get bytes by the long value

License

Open Source License

Parameter

Parameter Description
value a parameter
n a parameter
isLH a parameter

Declaration

public static byte[] getByteArrayByLong(long value, int n, boolean isLH) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w  ww  . ja v a  2  s  .c  om
     * get bytes by the long value. l before h after
     * 
     * @param value
     * @param n
     *            return bytes length
     * @return
     */
    public static byte[] getByteArrayByLong(long value, int n) {
        return getByteArrayByLong(value, n, true);
    }

    /**
     * get bytes by the long value
     * 
     * @param value
     * @param n
     * @param isLH
     * @return
     */
    public static byte[] getByteArrayByLong(long value, int n, boolean isLH) {
        byte[] dest = new byte[n];
        for (int i = 0; i < n; i++) {

            dest[i] = (byte) ((value >> ((isLH ? i : n - i - 1) * 8)) & 0xFF);
        }
        return dest;
    }
}

Related

  1. toBytes(long value)
  2. toBytes(long value, byte[] dest, int destPos)
  3. toByteArray(long val, byte[] b, int pos)
  4. toByteArray(long val, int w, byte[] b, int pos)
  5. getByteArrayByLong(long value, int n)
  6. getBytes(long data)
  7. uint32ToByteArrayLE(long value, byte[] output, int offset)
  8. uint64ToByteArrayLE(long value, byte[] output, int offset)
  9. long2byteArray(final long number, final int length, final boolean swapHalfWord)