Here you can find the source of intToByte(final int i)
Parameter | Description |
---|---|
i | integer |
public static byte intToByte(final int i)
//package com.java2s; /*/*from w w w .ja v a 2 s . co m*/ * #%L * utils-commons * %% * Copyright (C) 2016 - 2018 Gilles Landel * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ public class Main { private static final int HEX_FF = 0xFF; private static final int PERCENT_MAX = 100; /** * Convert an integer (0 to 255) into a byte (-128 to 127). * * @param i * integer * @return the byte */ public static byte intToByte(final int i) { int percent = (i * Byte.MAX_VALUE) / PERCENT_MAX; byte ret = (byte) (percent & HEX_FF); return ret; } }