Here you can find the source of toByteArrayFromLong(long longValue)
Parameter | Description |
---|---|
longValue | The long value which is to be converted to a byte array |
public static byte[] toByteArrayFromLong(long longValue)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Dr.-Ing. Marc M?ltin. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/* ww w. ja v a 2 s . c om*/ * Dr.-Ing. Marc M?ltin - initial API and implementation and initial documentation *******************************************************************************/ import java.nio.ByteBuffer; public class Main { /** * Converts a long (which in Java is a signed eight bytes value) into a byte array * @param longValue The long value which is to be converted to a byte array * @return The byte array corresponding to the given long value */ public static byte[] toByteArrayFromLong(long longValue) { return ByteBuffer.allocate(8).putLong(longValue).array(); } }