/*
input = 10111
output = 23
*/
import java.util.Scanner;
class GFG {
public static void main (String[] args) {
//System.out.println("GfG!");
Scanner scan = new Scanner(System.in);
String binaryNumber = scan.next();
String srr[] = binaryNumber.split("");
int arr[] = new int[srr.length];
int len = arr.length-1;
for(int i=0;i<arr.length;i++){
arr[len--] = Integer.parseInt(srr[i]);
}
int sum = 0;
for(int i = 0; i< arr.length ; i++){
sum += arr[i]*Math.pow(2,i);
}
System.out.println(sum);
}
}
x
No comments:
Post a Comment