Converting a hexadecimal (hex), octal, or binary value to an integer

Use the static method parseInt in the Integer primitive wrapper class. You pass in a string containing the digits of the specified radix. If a digit is not in the radix range, you’ll get a NumberFormatException.

Here’s an example:

public class Main
{
   public static void main(String args[]) {      
      // convert from hexadecimal                
      int a = Integer.parseInt("FF1C", 16);
  
      // convert from octal
      int b = Integer.parseInt("107", 8);
 
      // convert from binary
      int c = Integer.parseInt("10010", 2);
 
      System.out.println(a);   // 65308
      System.out.println(b);   // 71
      System.out.println(c);   // 18
   }
}