//************************************** // Name: Base10 Convertor // Description:A small project that converts decimal numbers to 6 different bases. Hope it maybe usfull. // By: Ben128 // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //************************************** // Base convert // By DreamVB 00:01 19/10/2016 #include <iostream> using namespace std; using std::cout; using std::endl; string BaseConvert(int decimal, int radix){ //Base convertor char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; string Ret = ""; int n = decimal; int base = 0; while (n >= radix){ base = (n % radix); n /= radix; Ret += hexmap[base]; } //Add last hexmap char Ret += hexmap[n]; //Reverse string std::reverse(Ret.begin(), Ret.end()); return Ret; } int main(int argc, char *argv[]){ int dec = 0; system("title Base10 Converting"); cout << "Enter a decimal number : "; cin >> dec; cout << endl; cout << "Binary : " << BaseConvert(dec, 2).c_str() << endl; cout << "Ternary : " << BaseConvert(dec, 3).c_str() << endl; cout << "Quinary : " << BaseConvert(dec, 5).c_str() << endl; cout << "Octonary: " << BaseConvert(dec, 8).c_str() << endl; cout << "Decimal : " << BaseConvert(dec, 10).c_str() << endl; cout << "Hexidecimal : " << BaseConvert(dec, 16).c_str() << endl; system("pause"); return 0; }