Byte.parseByte throws NumberFormatException for value "95", radix: 16

Janda Martin jandam at
Tue Jul 12 11:32:31 UTC 2011

I have question about parsing hex string. Java 6u25

When I call Byte.parseByte("95", 16) I get.

java.lang.NumberFormatException: Value out of range. Value:"95" Radix:16
	at java.lang.Byte.parseByte(

95 hex is 149 dec, Integer value '149' can be cast to valid byte value -107

Is the exception correct?

  Thank you very much for answer

 Martin JANDA
 jandam at

Code from

    public static byte parseByte(String s, int radix)
	throws NumberFormatException {
	int i = Integer.parseInt(s, radix);
	if (i < MIN_VALUE || i > MAX_VALUE)
	    throw new NumberFormatException(
                "Value out of range. Value:\"" + s + "\" Radix:" + radix);
	return (byte)i;

More information about the core-libs-dev mailing list