We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b2acf84 commit 028bf99Copy full SHA for 028bf99
binToDec.java
@@ -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