Java Long to Byte longToByte(long l)

Here you can find the source of longToByte(long l)

Description

Converts one long value to its byte value.

License

Open Source License

Parameter

Parameter Description
l The long value

Exception

Parameter Description
IllegalArgumentException when l is not in between 0 and 255.

Return

It's byte value

Declaration

public static byte longToByte(long l) throws IllegalArgumentException 

Method Source Code

//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;
    }
}

Related

  1. longToByte(byte[] buf, int off, long value)
  2. longToByte(final long value)
  3. longToByte(long a_value)
  4. longToByte(long i)
  5. longToByte(long i_Value)
  6. longToByte(long l)
  7. longToByte(long l)
  8. longToByte(long number)
  9. longToByte(long value)