Java Long to Byte Array longToByteArray(long value, byte[] byteArray)

Here you can find the source of longToByteArray(long value, byte[] byteArray)

Description

long To Byte Array

License

Open Source License

Declaration

public static final void longToByteArray(long value, byte[] byteArray) 

Method Source Code

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

public class Main {
    public static final void longToByteArray(long value, byte[] byteArray) {
        byteArray[7] = (byte) (value & 0xFF);
        byteArray[6] = (byte) ((value >>> 8) & 0xFF);
        byteArray[5] = (byte) ((value >>> 16) & 0xFF);
        byteArray[4] = (byte) ((value >>> 24) & 0xFF);
        byteArray[3] = (byte) ((value >>> 32) & 0xFF);
        byteArray[2] = (byte) ((value >>> 40) & 0xFF);
        byteArray[1] = (byte) ((value >>> 48) & 0xFF);
        byteArray[0] = (byte) (value >>> 56);
    }//  w  w  w  . ja va 2 s.  c om

    public static final void longToByteArray(long value, byte[] byteArray, int offset) {
        byteArray[7 + offset] = (byte) (value & 0xFF);
        byteArray[6 + offset] = (byte) ((value >>> 8) & 0xFF);
        byteArray[5 + offset] = (byte) ((value >>> 16) & 0xFF);
        byteArray[4 + offset] = (byte) ((value >>> 24) & 0xFF);
        byteArray[3 + offset] = (byte) ((value >>> 32) & 0xFF);
        byteArray[2 + offset] = (byte) ((value >>> 40) & 0xFF);
        byteArray[1 + offset] = (byte) ((value >>> 48) & 0xFF);
        byteArray[offset] = (byte) (value >>> 56);
    }
}

Related

  1. longToByteArray(long v)
  2. longToByteArray(long value)
  3. longToByteArray(long value)
  4. longToByteArray(long value)
  5. longToByteArray(long value, byte[] buffer, int offset)
  6. longToByteArray(long value, byte[] data, int offset)
  7. longToByteArray(long value, byte[] dest)
  8. longToByteArray(long value, int nrOfBytes)
  9. longToByteArray6(long addr)