Decode a string to a byte

decode() method accepts decimal, hexadecimal, and octal numbers given by the following grammar:

                          Signopt                      DecimalNumeral                      
                          Signopt                      0x HexDigits                      
                          Signopt                      0X HexDigits                      
                          Signopt                      # HexDigits                      
                          Signopt                      0 OctalDigits

The sign is :- .

public class Main {
  public static void main(String[] args) {
    System.out.println("Decimal 10:"+Byte.decode("10"));
    System.out.println("Octal 10:"+Byte.decode("010"));
    System.out.println("Hex F:"+Byte.decode("0XF"));
    System.out.println("Negative Hex F:"+Byte.decode("-0XF"));

The output:

Decimal 10:10
Octal 10:8
Hex F:15
Negative Hex F:-15
  Java Book 
    Essential Classes  

  1. Byte
  2. Find out byte's max value, min value and size
  3. Create Byte object with its constructor
  4. Convert Byte to byte, double, float, int, long and short
  5. Decode a string to a byte
  6. Byte class defines static methods to convert string value to byte value
  7. Convert byte value to string value
  8. Compare two byte values