Java Long to Byte Array long2bytes(long i, int byteCount)

Here you can find the source of long2bytes(long i, int byteCount)

Description

longbytes

License

Apache License

Declaration

public static byte[] long2bytes(long i, int byteCount) 

Method Source Code

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

public class Main {
    public static byte[] long2bytes(long i, int byteCount) {
        byte[] b = new byte[8];
        b[7] = (byte) (i);
        i >>>= 8;//from  w  ww .  j a  v  a  2s  . c  om
        b[6] = (byte) (i);
        i >>>= 8;
        b[5] = (byte) (i);
        i >>>= 8;
        b[4] = (byte) (i);
        i >>>= 8;
        b[3] = (byte) (i);
        i >>>= 8;
        b[2] = (byte) (i);
        i >>>= 8;
        b[1] = (byte) (i);
        i >>>= 8;
        b[0] = (byte) (i);

        byte[] bytes = new byte[byteCount];
        System.arraycopy(b, 8 - byteCount, bytes, 0, byteCount);
        return bytes;
    }
}

Related

  1. long2byteArray(long k, byte b[], int off)
  2. long2ByteArray(long l)
  3. long2ByteArray(long srcValue, int len)
  4. long2ByteLE(byte[] bytes, long value, int offset)
  5. long2bytes(long i)
  6. long2bytes(long i, int byteCount)
  7. long2bytes(long l, byte[] data, int offset)
  8. long2Bytes(long l, byte[] target, int offset)
  9. long2bytes(long longValue)