From 799a7de8555e8ffdc6f4d71bf444d87ea0856fd6 Mon Sep 17 00:00:00 2001 From: Akash Mondal Date: Sun, 8 Nov 2020 19:39:13 +0530 Subject: [PATCH] Fixes: #21 --- Conversions/DecimalToBinary.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Conversions/DecimalToBinary.java diff --git a/Conversions/DecimalToBinary.java b/Conversions/DecimalToBinary.java new file mode 100644 index 0000000..541a130 --- /dev/null +++ b/Conversions/DecimalToBinary.java @@ -0,0 +1,25 @@ +package Conversions; + +import java.util.ArrayList; + +public class DecimalToBinary { + + public static void main(String[] args) { + // Example to just show. + decimalToBcd(15); + } + /** + * Converts the decimal to Binary format. + * + * @input the integer that to be converted to binary. + */ + public static void decimalToBcd(int input) { + ArrayList num = new ArrayList(); + while (input > 0) { + int temp = input % 2; + input = input / 2; + num.add(0, temp); + } + System.out.println(num.toString()); + } +}