hi guys
i am trying to make a program to convert decimal number into binary .. i am able to do that, but the number comes inverted.. like 1101 comes like 1011
now how do i swap it off..
here is teh code
please help me
thanks
i am trying to make a program to convert decimal number into binary .. i am able to do that, but the number comes inverted.. like 1101 comes like 1011
now how do i swap it off..
here is teh code
Code:
import java.io.DataInputStream;
class dec2b{
public static void main(String a[]){
DataInputStream inp=new DataInputStream(System.in);
int nNum=0,nTemp=0,nSum=0,nBin=0,i=0;
System.out.println("Enter a Number to Convert into Binary");
try{nNum=Integer.parseInt(inp.readLine());}
catch(Exception e){}
while(nNum!=0)
{
nTemp=nNum;
if(nTemp%2==1)
nBin=1;
if(nTemp%2==0)
nBin=0;
nSum=nSum*10+nBin;
nNum=nNum/2;
}
System.out.println(nSum);
}}
thanks
Comment