I am trying to take ASCII from textBox1 and display the text in binary in textBox2. A simple ASCII to Binary converter.
private void button1_Click(object sender, EventArgs e)
{
byte[] inVAR = System.Text.Encoding.ASCII.GetBytes(textBox1.Text);
string outVAR = inVAR.ToString();
textBox2.Text = outVAR;
}
This of course results in the output being the same as the input, since I am converting the byte array back in to a readable string.
My question is how can I get the ASCII text to convert to binary but also a string type so that I can display it in the text box.
Essentially I am asking how do I create this ASCII to Binary converter because my method seems wrong.
Thanks!
Resolved! Thank you SLaks and OlimilOops:
textBox2.Text = string.Join(" ", inVAR.Select(b => Convert.ToString(b, 2).ToUpper()));