Skip to content

Commit 1c3490d

Browse files
authored
Update BinaryToDecimal.java
Updated some of the variable names for the ease of understanding the process.
1 parent 2bf163d commit 1c3490d

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 bin_num, bin_copy, 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+
bin_num = sc.nextInt();
21+
bin_copy = bin_num;
22+
while (bin_copy != 0) {
23+
d = bin_copy % 10;
24+
s += d * (int) Math.pow(2, power++);
25+
bin_copy /= 10;
2626
}
2727
System.out.println("Decimal equivalent:" + s);
2828
sc.close();

0 commit comments

Comments
 (0)