ava Byte class decode code Example
Byte class decode method example. This example shows you how to use decode method.
public static Byte decode(String nm) throws NumberFormatException Decodes a String into a Byte. Accepts decimal, hexadecimal, and octal numbers given by the following grammar: DecodableString: ------------------ Signopt DecimalNumeral Signopt 0x HexDigits Signopt 0X HexDigits Signopt # HexDigits Signopt 0 OctalDigits ------------------
Here is the code:
/** * @(#) Decode.java * A class representing decode method * @Version 03-May-2008 * @author Rose India Team */
public class Decode { public static void main(String args[]){ //decode method accepting decimal value as a string argument and Decoding into a Byte System.out.println(Byte.decode("127")); System.out.println(Byte.decode("-128")); //decode method accepting hexadecimal value as a string argument and Decoding into a Byte System.out.println(Byte.decode("0x7f")); System.out.println(Byte.decode("#7f"));
System.out.println(Byte.decode("-0x80")); System.out.println(Byte.decode("-#80")); //decode method accepting Octal value as a string argument and Decoding into a Byte System.out.println(Byte.decode("010")); System.out.println(Byte.decode("-010")); }
}
|