0

C#How can I take the hex value from a user and plug it into a byte array?

Byte[] mybyte = new byte[] { 0x11, 0x22 , 0x33, 0x44 }; I want the user to input the values between the pranthesis 0x11, 0x22, 0x33, 0x44 without using a loop. Basically I want the user to input either 11223344 or 0x11, 0x22, 0x33, 0x44 I want something like this: String h= Console.ReadLine(); Byte[] mybyte = new byte[] { h}; I know my example is wrong but how can I implemet it?

5th Jan 2019, 2:19 AM
Karzan
5 Answers
0
Rewa Mathur Thank you for answering but I don't want to to convert hex to string. I actually wanted the opposite. I want the user to enter a string and I take the same string and treat it like a hex. For example: if the user input ABCD as a string I want to keep the same valves but present them as hex values in a byte array. For example: Console.WriteLine("Enter a string value: "); String my_byte_array_hex_value = console.readline(); Byte[] mybyte = new byte[] { my_byte_array_hex_value}; In the other word whatever I input as a string must stay the same but get presented as a hex value.
5th Jan 2019, 5:05 AM
Karzan
0
Rewa Mathur can you please show an example because I have been chasing my tail with the code.
5th Jan 2019, 7:25 AM
Karzan