-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryToDecimal.java
More file actions
43 lines (41 loc) · 847 Bytes
/
BinaryToDecimal.java
File metadata and controls
43 lines (41 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Problem
// Result
// Binary to decimal
// Send Feedback
// Given a binary number as an integer N, convert it into decimal and print.
// Input format :
// An integer N in the Binary Format
// Output format :
// Corresponding Decimal number (as integer)
// Constraints :
// 0 <= N <= 10^9
// Sample Input 1 :
// 1100
// Sample Output 1 :
// 12
// Sample Input 2 :
// 111
// Sample Output 2 :
// 7
import java.util.Scanner;
/**
* BinaryToDecimal
*/
public class BinaryToDecimal {
public static void main(String[]args)
{
Scanner s = new Scanner(System.in);
int N = s.nextInt();
int ans=0;
int pow=0;
while(N!=0)
{
int rem = N%10;
ans+=Math.pow(2,pow)*rem;
N=N/10;
pow++;
}
System.out.println(ans);
s.close();
}
}