decimal Turn binary:
Decimal to Binary
#include <iostream>
using namespace std;
void printbinary (const unsigned int val)
{for
(int i = i >= 0; i--)
{
if (Val & (1 << i)) C9/>cout << "1";
else
cout << "0";
}
}
int main ()
{
printbinary (1024);
return 0;
}
Decimal Turn octal
Decimal transfer octal
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
cout<< "input a number:" <<endl;
int D;
Vector<int> Vec;
cin>>d;
while (d)
{
vec.push_back (d%8);
D=D/8;
}
cout<< "The result is:" <<endl;
For (Vector<int>::iterator ip=vec.end () -1;ip>=vec.begin ();)
{
cout<<*ip--;
}
cout<<endl;
return 0;
}
Decimal to arbitrary system:
Decimal conversion to arbitrary feed source
#include <iostream>
using namespace std;
int main ()
{
long n;
int p,c,m=0,s[100];
cout<< "Enter the number to convert:" <<endl;
cin>>n;
cout<< "Enter the system to convert:" <<endl;
cin>>p;
cout<< "(" <<n<< ") 10=" << "(";
while (n!=0)//conversion, the result is stored in the array s[m]
{
c=n%p;
n=n/p;
M++;s[m]=c; Put the remainder in order into array s[m]
} for
(int k=m;k>=1;k--)//output converted sequence
{
if (s[k]>=10)///If 16 is the output of the corresponding letter
cout<< (char) (s[k]+55);
else //Otherwise direct output digital
cout<<s[k];
}
cout<< ")" <<p<<endl;
return 0;
}
implements eight, hexadecimal output through library functions:
#include <iostream>
using namespace std;
int main ()
{
int test=64;
cout<< "DEC:" <<test<<endl;
cout<< "OCT:" <<oct<<test<<endl;//octal
cout<< "HEX:" <