From dd95658f7a19aed87970616c695342d712dd2a01 Mon Sep 17 00:00:00 2001 From: ASHISH KISHU <100489174+ashishkishu02@users.noreply.github.com> Date: Wed, 19 Oct 2022 11:07:28 +0530 Subject: [PATCH] adeed code code for binary decimal conversion --- binary decimal conversion | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 binary decimal conversion diff --git a/binary decimal conversion b/binary decimal conversion new file mode 100644 index 0000000..1499b70 --- /dev/null +++ b/binary decimal conversion @@ -0,0 +1,21 @@ +public class DecimalToBinaryExample2{ +public static void toBinary(int decimal){ + int binary[] = new int[40]; + int index = 0; + while(decimal > 0){ + binary[index++] = decimal%2; + decimal = decimal/2; + } + for(int i = index-1;i >= 0;i--){ + System.out.print(binary[i]); + } +System.out.println();//new line +} +public static void main(String args[]){ +System.out.println("Decimal of 10 is: "); +toBinary(10); +System.out.println("Decimal of 21 is: "); +toBinary(21); +System.out.println("Decimal of 31 is: "); +toBinary(31); +}}