i’m just started dev-ing app for wp7 and I’m trying to convert a string of binary back to ascii using c#.
But i have no idea how can it be done.
Hope someone could help me out here.
example :
Input string: 0110100001100101011011000110110001101111
Output string: hello
The simple solution,
using SubString and built in Convert.ToByte could look like this:
Another solution, doing the calculations yourself:
I added this in case you wanted to know how the calculations should be performed, rather than which method in the framework does it for you:
Where BitCharsToByte does the conversion from a char[] to the corresponding byte:
Both the above solutions does basically the same thing: First group the characters in groups of 8; then take that sub string, get the bits represented and calculate the byte value. Then use the ASCII Encoding to convert those bytes to a string.