Ask your own question, for FREE!
Computer Science 6 Online
OpenStudy (ifrah123):

what is the parse to convert decimal into binary numbers in java?

OpenStudy (rsmith6559):

Parse? The algorithm would be to divide by 2 and put the modulous as the first character of the answer until your number equals zero.

OpenStudy (shaik0124):

class DecimalBinaryExample{ public static void main(String a[]){ System.out.println("Binary representation of 124: "); System.out.println(Integer.toBinaryString(124)); System.out.println("\nBinary representation of 45: "); System.out.println(Integer.toBinaryString(45)); System.out.println("\nBinary representation of 999: "); System.out.println(Integer.toBinaryString(999)); } }

OpenStudy (shaik0124):

class DecimalBinaryExample{ public void convertBinary(int num){ int binary[] = new int[40]; int index = 0; while(num > 0){ binary[index++] = num%2; num = num/2; } for(int i = index-1;i >= 0;i--){ System.out.print(binary[i]); } } public static void main(String a[]){ DecimalBinaryExample obj = new DecimalBinaryExample(); System.out.println("Binary representation of 124: "); obj.convertBinary(124); System.out.println("\nBinary representation of 45: "); obj.convertBinary(45); System.out.println("\nBinary representation of 999: "); obj.convertBinary(999); } }

OpenStudy (shaik0124):

hope this two methods will solve your problem @ifrah123

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!