method to convert binary to decimal code example
Example 1: binary to integer in java
System.out.println(Integer.parseInt("1010",2));
Example 2: binary to decimal
import java.util.Scanner;
public class BinaryToDecimal {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String binary = sc.next();
System.out.println(Integer.parseInt(binary,2));
int n=0,dec=0;
for(int i=binary.length()-1;i>=0;i--)
{
dec = dec + Integer.parseInt(String.valueOf(binary.charAt(i)))*(int)Math.pow(2,n);
n++;
}
System.out.println(dec);
}
}