#include <iostream>
#include <iomanip>
#include <string>
using namespace std ;
// base 10 to any base between [2..36]
int main() {
// base 10 number
double number ; // 47.625 ;
cout << "块 10 秈疊翴计 : " ;
cin >> number ;
// number = c.d
int a , c = static_cast<int>(number) ;
double b , d = number - c ;
int tmp ;
int base ;
string no ;
for ( base = 2 ; base <= 16 ; ++base ) {
a = c ;
b = d ;
no = "" ;
while ( a != 0 ) {
tmp = a % base ;
no = ( tmp > 9 ?
static_cast<char>(tmp-10+'a') :
static_cast<char>(tmp+'0') ) + no ;
a /= base ;
}
no += '.' ;
for ( int i = 0 ; i < 10 ; ++i ) {
tmp = static_cast<int>(b*base) ;
b = b*base - tmp ;
no += ( tmp > 9 ?
static_cast<char>(tmp-10+'a') :
static_cast<char>(tmp+'0') ) ;
}
cout << setw(2) << base << " 秈 --> " << no << endl ;
}
return 0 ;
}
块 |
块 10 秈疊翴计 : 3.333
2 秈 --> 11.0101010100
3 秈 --> 10.0222222021
4 秈 --> 3.1111033313
5 秈 --> 3.1313030303
6 秈 --> 3.1555322404
7 秈 --> 3.2221350550
8 秈 --> 3.2523757473
9 秈 --> 3.2886727607
10 秈 --> 3.3330000000
11 秈 --> 3.37324a8a41
12 秈 --> 3.3bb5108092
13 秈 --> 3.4437a75212
14 秈 --> 3.493a756b91
15 秈 --> 3.4edd1d1d1d
16 秈 --> 3.553f7ced91
| |
|