From: Tony Johansson on
Hi!

If I have some bytes that are represented in hex like this.
12, bd,8f,7e,4e,4d. How do I assign all these bytes to a byte array ?
If the bytes were represented in decimal I would have been able to use this
statement
byte[] myBytes = new byte[]{ here I could have specified all the bytes with
comma in between };

But now when I have hex it's not possible. I could translate the hax value
into decimal but I hope there must be a better way.

//Tony


From: Jeff Johnson on
"Tony Johansson" <johansson.andersson(a)telia.com> wrote in message
news:OVyOOzU4KHA.5588(a)TK2MSFTNGP06.phx.gbl...

> If I have some bytes that are represented in hex like this.
> 12, bd,8f,7e,4e,4d. How do I assign all these bytes to a byte array ?
> If the bytes were represented in decimal I would have been able to use
> this statement
> byte[] myBytes = new byte[]{ here I could have specified all the bytes
> with comma in between };
>
> But now when I have hex it's not possible. I could translate the hax value
> into decimal but I hope there must be a better way.

Define "represented in hex." Do you mean you have a STRING containing hex
digits? If so, what does the string look like?


From: Tony Johansson on
"Jeff Johnson" <i.get(a)enough.spam> skrev i meddelandet
news:%236qTZfV4KHA.5416(a)TK2MSFTNGP06.phx.gbl...
> "Tony Johansson" <johansson.andersson(a)telia.com> wrote in message
> news:OVyOOzU4KHA.5588(a)TK2MSFTNGP06.phx.gbl...
>
>> If I have some bytes that are represented in hex like this.
>> 12, bd,8f,7e,4e,4d. How do I assign all these bytes to a byte array ?
>> If the bytes were represented in decimal I would have been able to use
>> this statement
>> byte[] myBytes = new byte[]{ here I could have specified all the bytes
>> with comma in between };
>>
>> But now when I have hex it's not possible. I could translate the hax
>> value into decimal but I hope there must be a better way.
>
> Define "represented in hex." Do you mean you have a STRING containing hex
> digits? If so, what does the string look like?

The string looks like this "12,bd,8f,7e,4e,4d" where each item in this
string 12 and db and 8f and so on should be converted to a byte and stored
in a byte array.

//Tony


From: Willem van Rumpt on
On 21-4-2010 19:23, Tony Johansson wrote:

>
> The string looks like this "12,bd,8f,7e,4e,4d" where each item in this
> string 12 and db and 8f and so on should be converted to a byte and stored
> in a byte array.
>

What solutions have you tried sofar?
Maybe if you post your failed attempts, we can help you solve it.

--
Willem van Rumpt
From: Jeff Johnson on
"Tony Johansson" <johansson.andersson(a)telia.com> wrote in message
news:eGsAedX4KHA.3352(a)TK2MSFTNGP02.phx.gbl...

>> Define "represented in hex." Do you mean you have a STRING containing hex
>> digits? If so, what does the string look like?
>
> The string looks like this "12,bd,8f,7e,4e,4d" where each item in this
> string 12 and db and 8f and so on should be converted to a byte and stored
> in a byte array.

Then you need to first use the Split() method with a comma as the delimiter
and then run each member of the resulting array through the byte.Parse()
method to get a real byte back. Use the overload that takes a numeric format
and specify <name of enum which I don't remember>.HexNumber.