32
1
using System;
2
using System.Text;
3
4
public class BinaryDecoder
5
{
6
public static string BinaryToUnicode(string binary)
7
{
8
// Ensure the binary string length is a multiple of 8
9
if (binary.Length % 8 != 0)
10
{
11
throw new ArgumentException("Binary string length must be a multiple of 8");
12
}
13
14
// Convert binary string to byte array
15
byte[] bytes = new byte[binary.Length / 8];
16
for (int i = 0; i < bytes.Length; i++)
17
{
18
string byteString = binary.Substring(i * 8, 8);
19
bytes[i] = Convert.ToByte(byteString, 2);
20
}
21
22
// Decode bytes as UTF-8
23
return Encoding.Unicode.GetString(bytes);
24
}
25
26
public static void Main()
27
{
28
string binaryString = "0100010101011000010100000100110001001111010100100100000101010100010010010100111101001110010011110100011101001000010101010100110101000001010011100100100101010100010110010011011001101100110110011100000110001001100000011000000110101001100100011000000111001001101000011001000110101001100110011001001001110001100010011001100110001001100110011000100110010001101100011100101010111010000110100111101001110010101000100100100101001110010101010100111101010101010100110101000110010011110101001001010000010011000100000101001110010001010101010001000001010100100101100101000001010001000101011001000001010011100001110010001001000010100011001001110101010101010100100101010001001000010000110100111101001111010001000100100101001110010000010101010001000101010000110100111101001110010101000100100101001110010101010100111101010100010101010101000101010011100100001101100010101010000010100100100001001000101010001100100111101010010010001010011001001101100011011100110110001100110011000100110111001101110100111000111000001110010011000100110001001101110011011100110110001110000101011100110011001101000011100000110000001100000011001000110111011001001001110001100010011000100110001001110000011010000110011011010100110110001101110101011100110010001110010011100100110111001101110011100000110011001101100100111000110011001100010011000100110011001100010011011000110100001110010100010100110001001101000011011100110000001100010011010100110000001101010101001100110111001101010011000100110110011011100110000011010000110011010101110011001100110110001100100011010100110110001110000011010000110101010011100011000100110001001101110011000100110000001100000011011000110011001100100100010100110011001101110011000100110001001100000011000100111001001101010100111000110010001101010011001100110111001100100011001000111000001100010100010101000101010110010100010101010011010011110100011001011001010011110101010101010010010001010101100101000010101010011010011110101001001001001010001110100100101001110001101010011001000110000011100100110100001100100011010100110011001100100100111000110001001100110011000100110011001100010011001000110110011100101010111010011110101001001001001010001110100100101001110010110010100010101000001010100100011100000110001001100000011000000000000000"; // add 6 0's at end
29
string text = BinaryToUnicode(binaryString);
30
Console.WriteLine(text); // Output: Hello
31
}
32
}
Cached Result