Java Integer to Byte intToByte(int value)

Here you can find the source of intToByte(int value)

Description

This function converts integer to one byte

License

Open Source License

Parameter

Parameter Description
value int type

Exception

Parameter Description
Exception Exception

Return

value

Declaration

public static final byte intToByte(int value) throws Exception 

Method Source Code

//package com.java2s;
/*/*from  w w  w.  java2s  . c om*/
 * Copyright (c) 2016 Tata Consultancy Services and others.  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
 */

public class Main {
    /**
     * This function converts integer to one byte
     * 
     * @param value
     *            int type
     * @return value
     * @throws Exception
     *             Exception
     */
    public static final byte intToByte(int value) throws Exception {
        if ((value > Math.pow(2, 15)) || (value < 0)) {
            throw new Exception("Integer value " + value + " is larger than 2^15");
        }
        return (byte) (value & 0xFF);
    }
}

Related

  1. intToByte(int number)
  2. intToByte(int number)
  3. intToByte(int number, int byteLength)
  4. intToByte(int v, byte[] dest)
  5. intToByte(int value)
  6. intToByte(int[] values)
  7. intToByte4(int number)
  8. intToByteArr(int v)