Java Long to Byte Array longToBytes(long num, byte[] data, int index)

Here you can find the source of longToBytes(long num, byte[] data, int index)

Description

long To Bytes

License

Open Source License

Declaration

public static byte[] longToBytes(long num, byte[] data, int index) 

Method Source Code

//package com.java2s;
/*/*from ww  w  . ja v  a2 s.c o m*/
 * @(#)ByteConvertUtil.java   V0.0.1 2015-2-3, ????1:37:07
 *
 * Copyright 2015 www.ifood517.com. All rights reserved.
 * www.ifood517.com PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {

    public static byte[] longToBytes(long num) {
        byte[] b = new byte[8];
        for (int i = 0; i < 8; i++) {
            b[i] = (byte) (num >> (56 - i * 8));
        }
        return b;
    }

    public static byte[] longToBytes(long num, byte[] data, int index) {
        for (int i = 0; i < 8; i++) {
            data[index + i] = (byte) (num >> (56 - i * 8));
        }
        return data;
    }
}

Related

  1. longToBytes(long lnum, byte[] bytes, int startIndex)
  2. longToBytes(long n)
  3. longToBytes(long n)
  4. longToBytes(long n, byte b[], int offset)
  5. longToBytes(long num)
  6. longToBytes(long number)
  7. longToBytes(long v)
  8. longToBytes(long v)
  9. longToBytes(long v, byte[] b)