3

I've got Textbox with a string like 89 3d 2c c0 7f 00

How to store it to Byte[] (byte array) variable ?

Now I can read only one dec value :(

Value=BitConverter.GetBytes(Int32.Parse(this.textBox3.Text.ToString()));

1 Answer 1

4

Use textBox3.Text.Split() to get an array of strings, each of length 2.

Then use byte.Parse(part, NumberStyles.HexNumber) in a loop to convert each part from hexadecimal to an integer.

Using LINQ it can be written like this:

byte[] result = textBox3.Text.Split(' ')
    .Select(part => byte.Parse(part, System.Globalization.NumberStyles.HexNumber))
    .ToArray();
Sign up to request clarification or add additional context in comments.

2 Comments

I no need to convert to integer , I need bit :-/
I think the only reason the Parse was in the quesiton is because he's using the BitConvertor. He doesn't really want the values as Ints.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.