I want to write the following sequence of bits in a textbox, like this:
000101100000000100000001000000010000000000100111001100010010000000110000001011100011000000110000001100000011000000100000001100110011100100101110001101110011010100100000001100000010111000110000001110000010000000110000001011100011000000110000001000000011000000101110001100000011000000110000001100000000010111010111
But every each 8 bits corresponds to a byte, so I want to store them in a byte[] array. Of course, if I read them like this:
byte[] byteBuffer = Encoding.ASCII.GetBytes(messageTextBox.Text);
Each 0 or 1 turns into a whole byte, which is not what I want.
Is there any straightforward solution, like some existing method, or I have to develop my own?
I have written the following code on the go without any compiler so please apologize syntax errors – also you have to take care of reaching the end of the text string on your own, its not included. I think the below method does what you want to do ..
If you want to save the decimal value that is represented by the binary value you have extracted from your string you can use this conversion method: