Octal To ASCII

This algorithm converts octal numbers to ASCII code.



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

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

static int OctalToDecimal(string octal) {
	int octLength = octal.length();
	double dec = 0;

	for (int i = 0; i < octLength; ++i)
	{
		dec += (octal[i] - 48) * pow(8, ((octLength - i) - 1));
	}

	return (int)dec;
}

static string OctalToASCII(string oct) {
	string ascii = "";
	int octLen = oct.length();

	for (int i = 0; i < octLen; i += 3)
	{
		ascii += (char)OctalToDecimal(oct.substr(i, 3));
	}

	return ascii;
}
								


Example

									string data = "120162157147162141155155151156147040101154147157162151164150155163";
string value = OctalToASCII(data);
								


Output

									Programming Algorithms