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 263e9ae commit 881697dCopy full SHA for 881697d
src/BitwiseOperators/BinaryToDecimal.java
@@ -0,0 +1,18 @@
1
+package BitwiseOperators;
2
+
3
+public class BinaryToDecimal {
4
+ public static void main(String[] args) {
5
+ /* Java In-built method */
6
+// String binary = "1010";
7
+// System.out.println(Integer.parseInt(binary, 2));
8
+ int n = 101001, pos = 0;
9
+ System.out.println(Integer.parseInt(Integer.toString(n), 2));
10
+ int decimal = 0;
11
+ while (n > 0){
12
+ // decimal = lastDigit * 2 ^ position;
13
+ decimal += n % 10 * (int) Math.pow(2, pos++);
14
+ n /= 10;
15
+ }
16
+ System.out.println(decimal); //10
17
18
+}
0 commit comments