Binary To ASCII
This algorithm converts binary numbers to ASCII code.
public static string BinaryToASCII(string bin)
{
string ascii = string.Empty;
for (int i = 0; i < bin.Length; i += 8)
{
ascii += (char)BinaryToDecimal(bin.Substring(i, 8));
}
return ascii;
}
private static int BinaryToDecimal(string bin)
{
int binLength = bin.Length;
double dec = 0;
for (int i = 0; i < binLength; ++i)
{
dec += ((byte)bin[i] - 48) * Math.Pow(2, ((binLength - i) - 1));
}
return (int)dec;
}
Example
string data = "01010000011100100110111101100111011100100110000101101101011011010110100101101110011001110010000001000001011011000110011101101111011100100110100101110100011010000110110101110011";
string value = BinaryToASCII(data);
Output
Programming Algorithms