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

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

Description

get bytes by the long value.

License

Open Source License

Parameter

Parameter Description
value a parameter
n return bytes length

Declaration

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

Method Source Code

//package com.java2s;

public class Main {
    /**//from   w ww  .  j  av  a 2s .co  m
     * 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. longs2bytesLE(long[] val)
  2. toBytes(long value)
  3. toBytes(long value, byte[] dest, int destPos)
  4. toByteArray(long val, byte[] b, int pos)
  5. toByteArray(long val, int w, byte[] b, int pos)
  6. getByteArrayByLong(long value, int n, boolean isLH)
  7. getBytes(long data)
  8. uint32ToByteArrayLE(long value, byte[] output, int offset)
  9. uint64ToByteArrayLE(long value, byte[] output, int offset)