Java Convert via ByteBuffer longToBytes(final long value)

Here you can find the source of longToBytes(final long value)

Description

long To Bytes

License

Open Source License

Declaration

public static byte[] longToBytes(final long value) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w.  j  ava  2  s  . c o m*/
 * Copyright (c) 2014. Donald Trummell. All Rights Reserved. Permission to use,
 * copy, modify, and distribute this software and its documentation for
 * educational, research, and not-for-profit purposes, without fee and without a
 * signed licensing agreement, is hereby granted, provided that the above
 * copyright notice, and this paragraph, appear in all copies, modifications,
 * and distributions. Contact dtrummell@gmail.com for commercial licensing
 * opportunities.
 */

import java.nio.ByteBuffer;

public class Main {
    public static final int BYTES_IN_LONG = Long
            .numberOfLeadingZeros(new Long(0l)) / 8;

    public static byte[] longToBytes(final long value) {
        return ByteBuffer.allocate(BYTES_IN_LONG).putLong(value).array();
    }
}

Related

  1. longTo4ByteArray(long n)
  2. longToByteArray(long l)
  3. longToByteArray(long value)
  4. longToByteArray(long value)
  5. longToByteArray(long[] array)
  6. longToBytes(long aLong)
  7. longToBytes(long l)
  8. longToBytes(long l, int size)
  9. longToBytes(long x)