publicstatic Byte decode(String nm) throws NumberFormatException { int radix =10; int index =0; boolean negative =false; Byte result; // Handle minus sign, if present if (nm.startsWith("-")) { negative =true; index++; } if (nm.startsWith("0x", index) || nm.startsWith("0X", index)) { index +=2; radix =16; }elseif (nm.startsWith("#", index)) { index++; radix =16; }elseif (nm.startsWith("0", index) && nm.length() >1+ index) { index++; radix =8; } if (nm.startsWith("-", index)) thrownew NumberFormatException("Negative sign in wrong position"); try{ result = Byte.valueOf(nm.substring(index), radix); result = negative ?new Byte((byte)-result.byteValue()) : result; }catch (NumberFormatException e) { // If number is Byte.MIN_VALUE, we'll end up here. The next line // handles this case, and causes any genuine format error to be // rethrown. String constant = negative ?new String("-"+ nm.substring(index)) : nm.substring(index); result = Byte.valueOf(constant, radix); } return result; }