vendredi 27 février 2015

String of bits to Unicode

I have a string of bits, like this string str = "0111001101101000" It's the letters"sh".

I need to make Unicode letters out of it. I'm doing following:



BitArray bn = new BitArray(str.Length); //creating new bitarray
for (int kat = 0; kat < str.Length; kat++)
{
if (str[kat].ToString() == "0")//adding boolean values into array
{
bn[kat] = false;
}
else
bn[kat] = true;
}

byte[] bytes = new byte[bn.Length];//converting to bytes
bn.CopyTo(bytes, 0);
string output = Encoding.Unicode.GetString(bytes); //encoding

textBox2.Text = output; // result in textbox


But the output text is just complete mess. How to do it right?


Aucun commentaire:

Enregistrer un commentaire