Java Long to Byte Array long2bytes(long i)

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

Description

longbytes

License

Open Source License

Declaration

public static byte[] long2bytes(long i) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static byte[] long2bytes(long i) {
        byte[] bytes = new byte[8];
        long2bytes(i, bytes, 0);
        return bytes;
    }/*from   ww  w .  ja  v a  2 s .c om*/

    public static void long2bytes(long i, byte[] bytes, int offset) {
        bytes[offset] = (byte) (i >>> 56);
        bytes[offset + 1] = (byte) (i >>> 48);
        bytes[offset + 2] = (byte) (i >>> 40);
        bytes[offset + 3] = (byte) (i >>> 32);
        bytes[offset + 4] = (byte) (i >>> 24);
        bytes[offset + 5] = (byte) (i >>> 16);
        bytes[offset + 6] = (byte) (i >>> 8);
        bytes[offset + 7] = (byte) i;
    }
}

Related

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