Java Long to Byte Array longToByteArray(long input)

Here you can find the source of longToByteArray(long input)

Description

Utility method for converting a long into a byte[]

License

Open Source License

Parameter

Parameter Description
input The log to convert

Return

a byte[] representation

Declaration

public static byte[] longToByteArray(long input) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  w w w  .j a v a 2 s.  c  o m*/
     * Utility method for converting a long into a byte[]
     *
     * @param input The log to convert
     * @return a byte[] representation
     */
    public static byte[] longToByteArray(long input) {
        byte[] output = new byte[8];
        longToByteArray(input, output, 0);
        return output;
    }

    /**
     * Utility method for converting a long into a byte[]
     *
     * @param input The log to convert
     * @return a byte[] representation
     */
    public static void longToByteArray(long input, byte[] output, int offset) {
        output[offset + 0] = (byte) (0xFF & (input >> 56));
        output[offset + 1] = (byte) (0xFF & (input >> 48));
        output[offset + 2] = (byte) (0xFF & (input >> 40));
        output[offset + 3] = (byte) (0xFF & (input >> 32));
        output[offset + 4] = (byte) (0xFF & (input >> 24));
        output[offset + 5] = (byte) (0xFF & (input >> 16));
        output[offset + 6] = (byte) (0xFF & (input >> 8));
        output[offset + 7] = (byte) (0xFF & input);
    }
}

Related

  1. longToByteArray(final long val, final byte[] buf, final int offset)
  2. longToByteArray(final long value, final int size)
  3. longToByteArray(long a, byte[] buf)
  4. longToByteArray(long i64)
  5. longToByteArray(long in)
  6. longToByteArray(long l)
  7. longToByteArray(long l)
  8. longToByteArray(long l)
  9. longToByteArray(long longHi, long longLo, byte[] array, int offset)