Here you can find the source of toBytes(final long val)
Parameter | Description |
---|---|
val | The 32-bit value to convert |
public static byte[] toBytes(final long val)
//package com.java2s; /* Penny Post - A postage system for email * Copyright (c) 2006-2007 Gregory Rubin <grrubin@gmail.com> * http://www.nettgryppa.com /*from w ww . j a va 2 s. c om*/ * Copyright (C) 2007 Aliasgar Lokhandwala <d7@freepgs.com> * http://pennypost.sourceforge.net/ * * CashUtils.java: Provides common helper methods * * 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 { /** * Converts a 32 bit value to an array of bytes. Reverse of * unsignedIntToLong * * @param val * The 32-bit value to convert * @return an array containing 4 bytes extracted from the value * * @author Ali * @see #unsignedIntToLong(byte[]) */ public static byte[] toBytes(final long val) { byte[] bytes = new byte[4]; bytes[3] = (byte) (val & 0xFF); bytes[2] = (byte) ((val & 0xFF00) >>> 8); bytes[1] = (byte) ((val & 0xFF0000) >>> 16); bytes[0] = (byte) ((val & 0xFF000000) >>> 32); return bytes; } }