Advertisement
Guest User

Universal Base Converter

a guest
Sep 13th, 2011
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string number,tempstring;
  9.     int degree_start, degree_end, len,temp,temp2,temp3,temp4;
  10.     string code = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  11.     cout << "Type the number" << endl;
  12.     cin >> number;
  13.     cout << "Type the degree of the number" << endl;
  14.     cin >> degree_start;
  15.     cout << "Type the degree of the converted number" << endl;
  16.     cin >> degree_end;
  17.     len = number.length();
  18.     temp =0;
  19.     for (int c=1;c<=len;c++)
  20.     {
  21.         tempstring=number.substr(len-c+1,1);
  22.         for(int d=1;d<=degree_start;d++)
  23.         {
  24.             if(tempstring==code.substr(d,1))
  25.                 temp2 = d;
  26.         }
  27.         temp = temp+(temp2-1)*(degree_start^(c-1));
  28.     }
  29.     tempstring = " ";
  30.     if(temp == 0)
  31.         tempstring = "0";
  32.     while (temp)
  33.     {
  34.         temp3 = temp-degree_end*(temp/degree_end);
  35.         tempstring = code.substr(temp+1,1) + tempstring;
  36.         temp = temp/degree_end;
  37.         if(temp < degree_end)
  38.         {
  39.             tempstring = code.substr(temp+1,1) + tempstring;
  40.             temp = 0;
  41.         }
  42.     }
  43.     cout << "Result:" << tempstring <<endl;
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement