Java Long to Byte Array longToBytes(long l, byte[] result)

Here you can find the source of longToBytes(long l, byte[] result)

Description

long To Bytes

License

Open Source License

Declaration

public static byte[] longToBytes(long l, byte[] result) 

Method Source Code

//package com.java2s;
/* //from   w  ww. ja v a  2 s.co  m
 * Copyright (c) 2014 RobotsByTheC. All rights reserved.
 *
 * Open Source Software - may be modified and shared by FRC teams. The code must
 * be accompanied by the BSD license file in the root directory of the project.
 */

public class Main {
    public static byte[] longToBytes(long i) {
        byte[] result = new byte[8];
        longToBytes(i, result);
        return result;
    }

    public static byte[] longToBytes(long l, byte[] result) {
        for (int i = Long.BYTES - 1; i >= 0; i--) {
            result[i] = (byte) (l & 0xFF);
            l >>= Byte.SIZE;
        }
        return result;
    }
}

Related

  1. longToBytes(long l)
  2. longToBytes(long l, byte[] arr, int startIdx)
  3. longToBytes(long l, byte[] b)
  4. longToBytes(long l, byte[] bytes, int offset)
  5. longToBytes(long l, byte[] data, int[] offset)
  6. longToBytes(long ldata, int n)
  7. longToBytes(long lnum, byte[] bytes, int startIndex)
  8. longToBytes(long n)
  9. longToBytes(long n)