Here you can find the source of longToBytes(long l, byte[] arr, int startIdx)
Parameter | Description |
---|---|
l | a Java long |
arr | a byte array, 8-bytes or longer |
startIdx | the start index into the array where the LONG should be written |
public static void longToBytes(long l, byte[] arr, int startIdx)
//package com.java2s; /*/*from w w w . jav a 2 s.c o m*/ * Copyright (C) 2014 Jesse Caulfield * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Unsigned Long to 8 bytes * * @param l a Java long * @param arr a byte array, 8-bytes or longer * @param startIdx the start index into the array where the LONG should be * written */ public static void longToBytes(long l, byte[] arr, int startIdx) { if (arr == null) { return; } int idx = startIdx; arr[idx++] = (byte) ((l >>> 56) & 0x00000000000000ff); arr[idx++] = (byte) ((l >>> 48) & 0x00000000000000ff); arr[idx++] = (byte) ((l >>> 40) & 0x00000000000000ff); arr[idx++] = (byte) ((l >>> 32) & 0x00000000000000ff); arr[idx++] = (byte) ((l >>> 24) & 0x00000000000000ff); arr[idx++] = (byte) ((l >>> 16) & 0x00000000000000ff); arr[idx++] = (byte) ((l >>> 8) & 0x00000000000000ff); arr[idx] = (byte) (l & 0x00000000000000ff); } }