Guest User

Untitled

a guest
Oct 12th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  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);
Add Comment
Please, Sign In to add comment