Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DecToBin{
- public static void main(String[] args){
- int dec = 64;
- int bin=0,rem=0;
- while(dec!=0){
- rem=dec%2;
- bin=bin*10+rem;
- dec=dec/2;
- }
- System.out.println("In Binary = "+bin);
- }
- }
- String s="";
- while(dec!=0)
- {
- rem=dec%2;
- s=(Integer.toString(rem)).concat(s);
- dec=dec/2;
- }
- System.out.println("In Binary = "+s);
- Integer.toString() //converts an integer to a string
- concat is used to add to strings.
- int binary_number=Integer.parseInt(s);
Add Comment
Please, Sign In to add comment