Here you can find the source of intToByte(int value)
Parameter | Description |
---|---|
value | int type |
Parameter | Description |
---|---|
Exception | Exception |
public static final byte intToByte(int value) throws Exception
//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); } }