From 57b924f1bf085d5ad283b67c9758d31531543222 Mon Sep 17 00:00:00 2001 From: Divyanshu Shukla <100156820+Divyanshu6566@users.noreply.github.com> Date: Mon, 10 Oct 2022 00:28:54 +0530 Subject: [PATCH] Binary_to_decimal conversion using java --- Hacktoberfest2022/Binary_to_decimal.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Hacktoberfest2022/Binary_to_decimal.java diff --git a/Hacktoberfest2022/Binary_to_decimal.java b/Hacktoberfest2022/Binary_to_decimal.java new file mode 100644 index 0000000..54edf7e --- /dev/null +++ b/Hacktoberfest2022/Binary_to_decimal.java @@ -0,0 +1,18 @@ +public class Binary_to_decimal { + public static void main(String[] args) { + long n = 101; + System.out.println(convert(n)); + } + public static int convert(long n){ + int decimal = 0, i =0; + + while (n != 0) { + long rem = n % 10; + decimal += rem * Math.pow(2, i); + n = n / 10; + i++; + } + return decimal; + + } +}