Binary to String Conversion in C#:
Binary data is a sequence of 1s and 0s, while strings are sequences of characters. In C#, the Encoding
class provides methods to facilitate this conversion.
using System;
using System.Text;
class BinaryToStringConverter
{
static void Main()
{
// Binary data as an array of bytes
byte[] binaryData = { 01001000, 01100101, 01101100, 01101100, 01101111, 00100000, 01000011, 01011101 };
// Convert binary data to string using UTF-8 encoding
string resultString = Encoding.UTF8.GetString(binaryData);
// Display the output
Console.WriteLine("Binary to String Conversion Result: " + resultString);
}
}
Output:
Binary to String Conversion Result: Hello C]
Comments (0)