Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Just compile this projects and follow guide
- #include <iostream>
- #include <string>
- #include <bits/stdc++.h>
- using namespace std;
- int ToDecimal(string input, int base) // перевод из любой в 10
- {
- int value = 0;
- int count = 1; // n^0=1 n^1=n*base n^1=n*base*base
- for(int i = input.length()-1; i >= 0; --i)
- {
- char c = input[i];
- if(c >= '0' && c <= '9')
- c -= 48;
- else
- c = c - 65 + 10;
- value += c * count;
- count *= base; // upper
- if(base != 10){
- cout << c*count; // stylising
- if (i != 0) cout << "+";} //stylising
- }
- if(base != 10){
- cout << "=" << value; //stylising
- cout << endl << endl;} //stylising
- return value;
- }
- string FromDecimal(int value, int base) // перевод из 10 в любую
- {
- string output;
- int temp, space = 0; //stylising
- int c = 0; //stylising
- while(value > 0)
- {
- char digit = value % base;
- if(digit < 10)
- digit += 48;
- else
- digit += 55;
- output += digit;
- temp = value;
- int ost = value % base;
- value /= base;
- // stylising start
- int temp1 = temp;
- int temp2 = value;
- int temp3 = ost;
- int c1 = 0;
- int c2 = 0;
- if(c>0) c++;
- for(;temp1>0;c++){
- temp1/=10;
- }
- for(;temp2>0;c1++){
- temp2/=10;
- }
- for(;temp3>0;c2++){
- temp3/=10;
- }
- for(int i=0; i<space; i++){
- cout << " ";
- }
- cout << temp << "|" << base << endl;
- for (int i=0; i<c; i++){
- cout << " ";
- }
- cout << "|";
- for (int i = 0 ; i<c1; i++) cout << "_" ;
- cout << endl;
- for (int i=0; i<(c-c2); i++){
- cout << " ";
- }
- cout << ost <<"|";
- //stylising end
- }
- reverse(output.begin(), output.end());
- cout <<endl << output;
- cout << endl << endl;
- return output;
- }
- string ConvertBase(string input, int baseFrom, int baseTo) //обьединяющая функция
- {
- return FromDecimal(ToDecimal(input, baseFrom), baseTo);
- }
- int main()
- {
- string number; // строка число
- int from, to; // из СС, в СС
- cout << "Input number, base from, base to in the next line \n"; // крутой коммент для вам
- cin >> number >> from >> to; // ввод
- cout << ConvertBase(number, from, to); // ебанешься крутая функция обьединяющая
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement