Bitset
Describe
Give you a number on base ten,you should output it on base two.(0 < n < 1000)
Input
For each case there is a postive number n on base ten, end of file.
Output
For each case output a number on base two.
Sample Input
1
2
3
Sample Output
1
10
11
十进制转二进制
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int num;
while(cin>>num)
{
if(!num)
{
cout<<"0"<<endl;
continue;
}
int two[100];
int n,i=0;
memset(two,0,sizeof(two));
while(num!=0)
{
n=num%2;
num/=2;
two[i++]=n;
}
for(i=i-1;i>=0;i--) cout<<two[i];
cout<<endl;
}
return 0;
}