Skip to content

Commit acb40ef

Browse files
authored
Merge pull request TheAlgorithms#791 from Priyansh-Kedia/master
Update BinaryToDecimal.java
2 parents 2bf163d + dc5ae2d commit acb40ef

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Conversions/BinaryToDecimal.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ class BinaryToDecimal {
1515
*/
1616
public static void main(String args[]) {
1717
Scanner sc = new Scanner(System.in);
18-
int n, k, d, s = 0, c = 0;
18+
int binNum, binCopy, d, s = 0, power = 0;
1919
System.out.print("Binary number: ");
20-
n = sc.nextInt();
21-
k = n;
22-
while (k != 0) {
23-
d = k % 10;
24-
s += d * (int) Math.pow(2, c++);
25-
k /= 10;
20+
binNum = sc.nextInt();
21+
binCopy = binNum;
22+
while (binCopy != 0) {
23+
d = binCopy % 10;
24+
s += d * (int) Math.pow(2, power++);
25+
binCopy /= 10;
2626
}
2727
System.out.println("Decimal equivalent:" + s);
2828
sc.close();

0 commit comments

Comments
 (0)