Here you can find the source of unpackUnsignedByte(byte b)
Parameter | Description |
---|---|
b | value in range -128 to 127 |
public static int unpackUnsignedByte(byte b)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w .j av a 2 s .c om*/ * Since byte is a signed type you cannot receive the unsigned value * even if you do {@code (byte) 200}. This method will return {@code 200} * in this case instead of a negative one. * <p> * Applied mapping: * [0..127] to [0..127] and [-128..-1] to [128..255] * * @param b value in range -128 to 127 * @return value in range 0 to 255 */ public static int unpackUnsignedByte(byte b) { // byte: 0 - 127 => 0 - 127, 128 - 255 => -128 - -1 return b >= 0 ? b : b + 256; } }