Decode a string to a byte

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

SignValue
SignoptDecimalNumeral
Signopt0x HexDigits
Signopt0X HexDigits
Signopt# HexDigits
Signopt0 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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.