Question: How can I improve this code so that the result becomes 8 digit binary. and how this code can make decimal 0 into 8 bit

 How can I improve this code so that the result becomes

How can I improve this code so that the result becomes 8 digit binary. and how this code can make decimal 0 into 8 bit binary

public class Binary { public static void main(String[] args) { int number; Scanner sc = new Scanner(System.in); ArrayList binary = new ArrayList(); System.out.println("Enter a decimal number: "); number = sc.nextInt(); int a =number; int remainder; int sum=0; int k=1; while(a!=0) { remainder-a%2; a/=2; sum=sum+remainder*k; k*=10; } System.out.println("The decimal number "+number+" is "+sum+" in binary."); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!