#include<iostream.h> #include<math.h> void f1(int m, int n) { // Conversion part if(m) {
f1(m/n,n); if(n<10) cout<<m%n; else m%n>=10? cout<<char(m%n-10+'A') :
cout<<m%n; } } void f2(double m, int n) { // Decimal part while(m) { if(n<10)
cout<<int(m*n); else m*n>=10? cout<<char(int(m*n)-10+'A') : cout<<int(m*n); m =
m*n - int(m*n); } } void f(double m, int n) { f1(m, n); if(int(m) == m) return;
cout<<'.'; m -= int(m); f2(m, n); } void f10(char c[], double m) { cout<<'
'<<c<<" convert to "<< 2<<" System = "; f(m, 2); cout<<endl; cout<<' '<<c<<" convert to "<< 8<<" System =
"; f(m, 8); cout<<endl; cout<<' '<<c<<" convert to "<<16<<" System = "; f(m,16); cout<<endl;
} double fn_10(char c[], int n) { char z[100]; int i = 0, j; double b = 0;
cout<<' '<<c<<" convert to 10 System = "; while(*c != '.' && *c != '\0') z[i++] = *c++; i--;
if(*c == '\0') c--; for(j = 0; j <= i; j++) if(z[j] < 65) b += (z[j]-48) *
pow(n,i-j); else b += (z[j]-55) * pow(n,i-j); for(c++, j = -1; *c != '\0' ;
c++, j--) if(*c < 65) b += (*c-48) * pow(n,j); else b += (*c-55) * pow(n,j);
cout<<b<<endl; return b; } void main() { cout<<" Base conversion \n"; char c[100]; int n;
cout<<"\n Enter a number and its base number : "; cin>>c>>n; cout<<endl; f10(c, fn_10(c,n)); }

A brief introduction to the idea of converting decimal system to binary system :

1. Iterate to the bottom , The lowest remainder is the highest , There is no residue at the bottom ;

2. Recurs to the top in turn , The remainder of each time is the low order of its bottom , Its upper high position ;

3. All the way back to the top , After getting all the data , Output remainder in reverse order , It is the solution after the conversion .

Technology
©2019-2020 Toolsou All rights reserved,
Java Swing JList: List box components Accurate mobile phone number capture , Big data of operators The difference between memory overflow and memory leak , Causes and Solutions Website mobile phone number capture method stay Vue Use in Web Worker3 species Python data structure ,13 Creation methods , This is the conclusion , Great ! What's the difference in server prices ? Basic definition and use of function ‘ To be continued SQL Server Database Glossary Chrome OS, For programmers and Windows What does it mean ? Internet Marketing