English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java program converts a binary number to a decimal number

parseInt()Because the second parameter is the base value, so use the second parameter as2method. TheparseInt()The method has the following two forms.

static int parseInt(String s)
static int parseInt(String s, int radix)

To convert binary to decimal, please use2nd syntax and add the base value as2Because the binary base is2.

Integer.parseInt("1110", 2)

Example

public class Demo {
   public static void main(String args[]) {
      //Convert to Decimal
      System.out.println(Integer.parseInt("1110", 2));
   }
}

Output Result

14