Program to convert a Decimal number into its Binary Equivalent.
Example : Input : 13
Output : 1101
Input : 8
Output : 1000
The video link of this program is provided at the end of this post.
Program :-
import java.io.*; import java.util.*; class Binary { public static void main(String args[]) { Scanner in = new Scanner(System.in); int n,p,a; String str=""; System.out.println("Enter Number to Convert it into Binary"); n= in.nextInt(); p=n; while(p>0) { a=p%2; str=a+str; p=p/2; } System.out.println("Original Number : "+n); System.out.println("Binary Form : "+str); } };
Note : The program is written in the easiest way possible so try understand it. If you face any problem in understanding this program than feel free to contact/comment.
Comments