I need to convert a string into it’s binary equivilent and keep it in a string. Then return it back into it’s ASCII equivalent.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can encode a string into a byte-wise representation by using an
Encoding, e.g. UTF-8:To get back a .NET string object:
You seem to want the representation as a series of
'1'and'0'characters; I’m not sure why you do, but that’s possible too:Encodings take an abstract string (in the sense that they’re an opaque representation of a series of Unicode code points), and map them into a concrete series of bytes. The bytes are meaningless (again, because they’re opaque) without the encoding. But, with the encoding, they can be turned back into a string.
You seem to be mixing up “ASCII” with strings; ASCII is simply an encoding that deals only with code-points up to 128. If you have a string containing an
'é', for example, it has no ASCII representation, and so most definitely cannot be represented using a series of ASCII bytes, even though it can exist peacefully in a .NETstringobject.See this article by Joel Spolsky for further reading.