Java Program To Convert Decimal To Binary
Chapter:
Interview Programs
Last Updated:
14-07-2016 07:56:18 UTC
Program:
/* ............... START ............... */
public class JavaDecimalToBinary {
public static void main(String a[]) {
System.out.println("Binary representation of 300: ");
System.out.println(Integer.toBinaryString(300));
System.out.println("\nBinary representation of 8: ");
System.out.println(Integer.toBinaryString(8));
System.out.println("\nBinary representation of 7: ");
System.out.println(Integer.toBinaryString(7));
}
}
/* ............... END ............... */
Output
Binary representation of 300:
100101100
Binary representation of 8:
1000
Binary representation of 7:
111
Notes:
-
An easy method of converting decimal to binary number equivalents is to write down the decimal number and to continually divide-by-2 (two) to give a result and a remainder of either a “1” or a “0” until the final result equals zero.
Tags
Convert Decimal To Binary, Java