Here you can find the source of longToByte(long l)
Parameter | Description |
---|---|
l | The long value |
Parameter | Description |
---|---|
IllegalArgumentException | when l is not in between 0 and 255. |
public static byte longToByte(long l) throws IllegalArgumentException
//package com.java2s; public class Main { /**/*from w w w. j av a 2 s. com*/ * Converts one long value to its byte value. * * @param l The long value * @return It's byte value * @throws IllegalArgumentException when l is not in between 0 and 255. * * @see #longToByte(long[]) * @since 4_14 */ public static byte longToByte(long l) throws IllegalArgumentException { byte ret = 0; if ((l < 0) || (l > 255)) { throw new IllegalArgumentException("Valid byte values are between 0 and 255." + "Got " + l); } ret = (byte) (l); return ret; } /** * Converts an array of long values to its array of byte values. * * @param l The array of longs * @return The array of bytes * @throws IllegalArgumentException when one of the longs is not in between 0 and 255. * * @see #longToByte(long) * @since 4_14 */ public static byte[] longToByte(long[] l) throws IllegalArgumentException { int len = l.length; byte[] ret = new byte[len]; for (int i = 0; i < len; i++) { ret[i] = longToByte(l[i]); } return ret; } }