Skip to content

Commit d584c45

Browse files
BinarytoDecimal.java
1 parent 25a5644 commit d584c45

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

BinarytoDecimal.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class BinarytoDecimal
2+
{
3+
public static int check(int n){
4+
int power=0;
5+
int dec=0;
6+
while(n!=0){
7+
int lastdigit=n%10;
8+
dec=dec+lastdigit*(int)Math.pow(2,power);
9+
power++;
10+
n=n/10;
11+
}
12+
return dec;
13+
}
14+
public static void main(String[] args) {
15+
System.out.println(check(101));
16+
17+
18+
}
19+
}

0 commit comments

Comments
 (0)