Skip to content

Commit 0252572

Browse files
committed
Added Binary to Decimal conversion.
1 parent dc82c09 commit 0252572

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Binary to Decimal.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#import java.util.*;
2+
class Binary_Decimal
3+
{
4+
public static void main(String args[])
5+
{
6+
Scanner sc=new Scanner(System.in);
7+
int n,k,d,s=0,c=0;
8+
n=sc.nextInt();
9+
k=n;
10+
while(k!=0)
11+
{
12+
d=k%10;
13+
s+=d*(int)Math.pow(2,c++);
14+
k/=10;
15+
}
16+
System.out.println("Binary number:"+n);
17+
System.out.println("Decimal equivalent:"+s);
18+
}
19+
}

0 commit comments

Comments
 (0)