Home Forums C Programming convert decimal to binary Re: Re: convert decimal to binary

#3600
GWILouisaxwzkla
Participant

could try this:


#include

void main()
{

int i;
cout << "Enter a number to convert ";
cin >> i;
int binaryArray [ 20 ] ; //whatever
int j = 0;
while ( i )
{
binaryArray [ j ++ ] = i % 2 ;
i /= 2;
}

cout << endl << "Binary Version: " ;
while ( j -- > 0 )
cout << binaryArray [ j ];
cout << endl;
}