SHARE
TWEET

Untitled




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);
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.