converting decimal to 16 bit binary

I am having some issues with this program. I will put the program below and my code.

Change your binary conversion program to use the design using iteration we discussed in class. Do
NOT write 16 if-else statements to handle each bit. This time, use the range 0 to 65,535 (range for
unsigned binary, 16 bits). Be sure to check for proper range before you attempt to convert the number to
binary. After you convert the current number, ask the user if he’d like to give another number to convert.
Figure out how to write the binary output so that there is a space after every set of 4 binary digits.
200 converted to binary : 0000 0000 1100 1000
Your sample output should include the following:
200, 63, 255, 144, -1, 1024, 65000, 100000, and 65535

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main() {

int value, powerof2;

do {
cout << "Enter a value between 0 and 65,535: " << endl;
cin >> value;
} while (value < 0 || value > 65535)

powerof2 = pow(2, 5) * 32768;

while (powerof2 > 0)
if (value >= powerof2)
cout << '1';
value = value - powerof2;
else
cout << '0';
powerof2 = powerof2 / 2;

}
return 0;
I have to set it up like this but for some reason the pow is not working
Topic archived. No new replies allowed.