Here you can find the source of longToByteArray(long v)
Parameter | Description |
---|---|
v | long value to convert |
public static byte[] longToByteArray(long v)
//package com.java2s; /* Copyright (c) 2011-2013 Pushing Inertia * All rights reserved. http://pushinginertia.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.//from w w w . j a v a 2s . c o m */ public class Main { /** * Converts a long to a byte array of length 8 * @param v long value to convert * @return a byte array of length 8 */ public static byte[] longToByteArray(long v) { final byte[] writeBuffer = new byte[8]; writeBuffer[0] = (byte) (v >>> 56); writeBuffer[1] = (byte) (v >>> 48); writeBuffer[2] = (byte) (v >>> 40); writeBuffer[3] = (byte) (v >>> 32); writeBuffer[4] = (byte) (v >>> 24); writeBuffer[5] = (byte) (v >>> 16); writeBuffer[6] = (byte) (v >>> 8); writeBuffer[7] = (byte) (v >>> 0); return writeBuffer; } }