binary to decimal calculator online code example
Example 1: 10 binary to denary
binary 10 = 2 denary
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);
}
}