Reading an array of bytes Text box & # 8594; byte []

I have a text box with a type string 89 3d 2c c0 7f 00

How to save it in byte variable [] (byte array)?

Now I can read only one dec value :(

Value=BitConverter.GetBytes(Int32.Parse(this.textBox3.Text.ToString()));
+3
source share
1 answer

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

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

Using LINQ, it can be written as follows:

byte[] result = textBox3.Text.Split(' ')
    .Select(part => byte.Parse(part, System.Globalization.NumberStyles.HexNumber))
    .ToArray();
+4
source

Source: https://habr.com/ru/post/1732011/


All Articles