Here you can find the source of longToByteArray(long value)
Parameter | Description |
---|---|
value | Long value to convert to byte array. |
public static byte[] longToByteArray(long value)
//package com.java2s; /**//from w ww . ja v a 2 s . com * Copyright (c) 2014-2016 Digi International Inc., * All rights not expressly granted are reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. * * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 * ======================================================================= */ public class Main { /** * Converts the given long value into a byte array. * * @param value Long value to convert to byte array. * * @return Byte array of the given long value (8 bytes length). * * @see #byteArrayToLong(byte[]) */ public static byte[] longToByteArray(long value) { return new byte[] { (byte) ((value >>> 56) & 0xFF), (byte) ((value >>> 48) & 0xFF), (byte) ((value >>> 40) & 0xFF), (byte) ((value >>> 32) & 0xFF), (byte) ((value >>> 24) & 0xFF), (byte) ((value >>> 16) & 0xFF), (byte) ((value >>> 8) & 0xFF), (byte) (value & 0xFF) }; } }