Decimal To Hexadecimal

This algorithm converts decimal numbers to hexadecimal numbers.



									/*****Please include following header files*****/
// string
/***********************************************/

/*****Please use following namespaces*****/
// std
/*****************************************/

static string DecimalToHexadecimal(int dec) {
	if (dec < 1) return "0";

	int hex = dec;
	string hexStr = "";

	while (dec > 0)
	{
		hex = dec % 16;

		if (hex < 10)
			hexStr = hexStr.insert(0, string(1, (hex + 48)));
		else
			hexStr = hexStr.insert(0, string(1, (hex + 55)));

		dec /= 16;
	}

	return hexStr;
}
								


Example

									int data = 484879;
string value = DecimalToHexadecimal(data);
								


Output

									7660F