0 Replies - 76 Views - Last Post: 10 July 2008 - 05:05 PM

#1 captainhampton   User is offline

  • Jawsome++;
  • member icon

Reputation: 15
  • View blog
  • Posts: 548
  • Joined: 17-October 07

Hexavigesimal Conversion (Base 10 to Base 26)

Posted 10 July 2008 - 05:05 PM

Description: Convert a Base 10 number to a Base 26 equivalentConvert 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-25n"; 
			exit(1);
	}//endif
	base26(num);

	return 0;
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1