Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 57 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. class DecToBin{
  2.     public static void main(String[] args){
  3.     int dec = 64;
  4.     int bin=0,rem=0;
  5.     while(dec!=0){
  6.         rem=dec%2;
  7.         bin=bin*10+rem;
  8.         dec=dec/2;
  9.     }
  10.     System.out.println("In Binary = "+bin);
  11.   }
  12. }
  13.    
  14. String s="";
  15. while(dec!=0)
  16. {
  17.     rem=dec%2;
  18.     s=(Integer.toString(rem)).concat(s);
  19.     dec=dec/2;
  20. }
  21. System.out.println("In Binary = "+s);
  22.    
  23. Integer.toString() //converts an integer to a string
  24. concat is used to add to strings.
  25.    
  26. int binary_number=Integer.parseInt(s);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top