How to Convert Binary Encoded Strings to Normal Strings in C#?
The below C# program converts a binary encoded string to normal string in C,:
using System;
using System.Text;
class BinaryDecoder
{
static string BinaryToString(string binaryString)
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < binaryString.Length; i += 8)
{
string binaryByte = binaryString.Substring(i, 8);
byte asciiByte = Convert.ToByte(binaryByte, 2);
result.Append((char)asciiByte);
}
return result.ToString();
}
static void Main()
{
string binaryEncodedString = "01010100011001010110001101101000011010010110010101001000011011110110111101101011";
string decodedString = BinaryToString(binaryEncodedString);
Console.WriteLine("Binary Encoded String: " + binaryEncodedString);
Console.WriteLine("Decoded String: " + decodedString);
Console.ReadKey();
}
}
Output:
Binary Encoded String: 01010100011001010110001101101000011010010110010101001000011011110110111101101011
Decoded String: TechieHook
Comments (0)