hi!
I need to write a progam that will convert a number to binary.
Example
user enters number between 0 and 15
output is the value of the number returned to screen
and then the output in binary returned to the screen
thank you!
Printable View
hi!
I need to write a progam that will convert a number to binary.
Example
user enters number between 0 and 15
output is the value of the number returned to screen
and then the output in binary returned to the screen
thank you!
Here's one solution -
#include <iostream>
#include <bitset>
using namespace std;
However, if this is a homework assignment then I doubt that this will be the answer you're looking for. Let's see what you've done so far.Code:#include <iostream>
#include <bitset>
using namespace std;
int main()
{
int i =0;
do
{
cin >>i;
}while (i<0 || i>15);
//need four bits to represent 0-15
bitset <4> j = i;
cout << i << " = " << j << endl;
return 0;
}
Are you allowed to use itoa()?
Quote:
Originally posted by zoo
Are you allowed to use itoa()?
Thanks for your reply. some has already helped me.