Skip to content

Commit

Permalink
fixed the issue Binary To Decimal DHEERAJHARODE#2746
Browse files Browse the repository at this point in the history
added a class BIN to DEC and a function converts Binary number to decimal number
  • Loading branch information
iamdk353 authored Oct 15, 2024
1 parent 1c86990 commit fef4911
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions BinToDecimal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.
public class BinToDecimal {
public static int convertBinaryToDecimal(int binary) {
int decimal = 0;
int base = 1;

while (binary > 0) {
int lastDigit = binary % 10;
decimal += lastDigit * base;
binary = binary / 10;
base = base * 2;
}
return decimal;
}
}

0 comments on commit fef4911

Please sign in to comment.