Skip to content

Commit 028bf99

Browse files
authored
Added binToDec.java
Binary to Decimal conversion Please review my code and merge it. thank you!!
1 parent b2acf84 commit 028bf99

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

binToDec.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.Scanner;
2+
3+
public class binToDec {
4+
5+
6+
public static void binToDecConversion(int binNum){
7+
int myNum = binNum;
8+
int pow = 0;
9+
int decNum = 0;
10+
11+
while(binNum > 0){
12+
int lastDigit = binNum % 10;
13+
decNum = decNum + (lastDigit * (int)Math.pow(2, pow));
14+
pow++;
15+
16+
binNum = binNum / 10;
17+
}
18+
System.out.println("decimal of " + myNum + " = " + decNum);
19+
20+
}
21+
public static void main(String args[]){
22+
Scanner sc = new Scanner(System.in);
23+
24+
binToDecConversion(100);
25+
sc.close();
26+
}
27+
}

0 commit comments

Comments
 (0)