#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,
Final review of database : Summary of comprehensive application questions use Python Make simple games Laplance operator ( Second derivative ) Convert hard disk to GPT Partition format Python Implementation of Hanoi Tower code about String How to create objects vue3 Learning journey 1—— establish vue3 project java String from back to front _Java String String summary use Python Write a story about plants versus zombies 【 Greedy Algorithm 】 Huffman coding problem