Skip to content

Commit fef4911

Browse files
authored
fixed the issue Binary To Decimal DHEERAJHARODE#2746
added a class BIN to DEC and a function converts Binary number to decimal number
1 parent 1c86990 commit fef4911

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

BinToDecimal.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This issue is for adding a new Java class BinTODecimal in the Maths package. The class contains a method to convert a binary number (provided as an integer) to its decimal equivalent. The goal is to provide functionality for binary-to-decimal conversion using basic mathematical operations.
2+
public class BinToDecimal {
3+
public static int convertBinaryToDecimal(int binary) {
4+
int decimal = 0;
5+
int base = 1;
6+
7+
while (binary > 0) {
8+
int lastDigit = binary % 10;
9+
decimal += lastDigit * base;
10+
binary = binary / 10;
11+
base = base * 2;
12+
}
13+
return decimal;
14+
}
15+
}

0 commit comments

Comments
 (0)