From 1c3490d25e8e920efc83890a5336ac89af28220b Mon Sep 17 00:00:00 2001 From: Priyansh-Kedia <52661249+Priyansh-Kedia@users.noreply.github.com> Date: Tue, 9 Jul 2019 23:06:40 +0530 Subject: [PATCH 1/2] Update BinaryToDecimal.java Updated some of the variable names for the ease of understanding the process. --- Conversions/BinaryToDecimal.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Conversions/BinaryToDecimal.java b/Conversions/BinaryToDecimal.java index 91f1b7bc..24205534 100644 --- a/Conversions/BinaryToDecimal.java +++ b/Conversions/BinaryToDecimal.java @@ -15,14 +15,14 @@ class BinaryToDecimal { */ public static void main(String args[]) { Scanner sc = new Scanner(System.in); - int n, k, d, s = 0, c = 0; + int bin_num, bin_copy, d, s = 0, power = 0; System.out.print("Binary number: "); - n = sc.nextInt(); - k = n; - while (k != 0) { - d = k % 10; - s += d * (int) Math.pow(2, c++); - k /= 10; + bin_num = sc.nextInt(); + bin_copy = bin_num; + while (bin_copy != 0) { + d = bin_copy % 10; + s += d * (int) Math.pow(2, power++); + bin_copy /= 10; } System.out.println("Decimal equivalent:" + s); sc.close(); From dc5ae2d03bdf974100ab0551045c4526ac6da7b5 Mon Sep 17 00:00:00 2001 From: Priyansh-Kedia <52661249+Priyansh-Kedia@users.noreply.github.com> Date: Wed, 10 Jul 2019 10:17:08 +0530 Subject: [PATCH 2/2] Update BinaryToDecimal.java Changed bin_num and bin_copy to binNum and binCopy respectively. --- Conversions/BinaryToDecimal.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Conversions/BinaryToDecimal.java b/Conversions/BinaryToDecimal.java index 24205534..6db926d3 100644 --- a/Conversions/BinaryToDecimal.java +++ b/Conversions/BinaryToDecimal.java @@ -15,14 +15,14 @@ class BinaryToDecimal { */ public static void main(String args[]) { Scanner sc = new Scanner(System.in); - int bin_num, bin_copy, d, s = 0, power = 0; + int binNum, binCopy, d, s = 0, power = 0; System.out.print("Binary number: "); - bin_num = sc.nextInt(); - bin_copy = bin_num; - while (bin_copy != 0) { - d = bin_copy % 10; + binNum = sc.nextInt(); + binCopy = binNum; + while (binCopy != 0) { + d = binCopy % 10; s += d * (int) Math.pow(2, power++); - bin_copy /= 10; + binCopy /= 10; } System.out.println("Decimal equivalent:" + s); sc.close();