Convert a Base 10 number to a Base 26 equivalent
#include <iostream>
using namespace std; void base26(int num){ string hex = ""; int ret = 0; while ( num > 25 ){ int i = num % 26; num = num / 26; ret = atoi(hex.c_str()); hex = (char)(i+97)+ret; } hex = (char)(num+97) + ret; for ( int i = 0; i < hex.size(); i++ ) cout << hex[i]; } int main(){ int num; cout << "Enter base 10(1-25) number to convert to base 26 (Hexavigesimal):\n"; cin >> num; if ( num > 25 ){ cout << "Error must be 1-25\n"; exit(1); }//endif base26(num); return 0; }
Tidak ada komentar:
Posting Komentar