Solved

# Converting Decimal to Binary

Posted on 2004-08-05

My program transforms decimal numbers to binary representation. But I need it to transform it to 16 bit binary representation, mine only transforms to regular binary.

For example, Mine: 25 = 11001 but it should be 0000000000011001. This is my program:

#include <iostream>

using namespace std;

void dectobin(int num, int base);

int main()

{

int decimalnum;

int base;

base = 2;

cout<<"Enter the number in decimal: ";

cin>>decimalnum;

cout<<endl;

cout<<"Decimal: "<<decimalnum<<" = ";

dectobin(decimalnum, base);

cout<< " Binary" <<endl;

return 0;

}

void dectobin(int num, int base)

{

if(num > 0)

{

dectobin(num/base, base);

cout<<num % base;

}

}

What do I have to do to make it print out the remaining digits? Please Advise