ASCII To Octal
This algorithm converts ASCII code to octal numbers.
public static string ASCIIToOctal(string str)
{
string oct = string.Empty;
for (int i = 0; i < str.Length; ++i)
{
string cOct = DecimalToOctal(str[i]);
if (cOct.Length < 3)
cOct = cOct.PadLeft(3, '0');
oct += cOct;
}
return oct;
}
private static string DecimalToOctal(int dec)
{
if (dec < 1) return "0";
string octStr = string.Empty;
while (dec > 0)
{
octStr = octStr.Insert(0, (dec % 8).ToString());
dec /= 8;
}
return octStr;
}
Example
string data = "Programming Algorithms";
string value = ASCIIToOctal(data);
Output
120162157147162141155155151156147040101154147157162151164150155163