0

New here and very novice so pardon any terminology errors...

I have a string that represents (literally) a hex byte array that I need to convert to a byte array. for example string a = "8400081A" that I need to convert to a byte array of exactly the same {0x84, 0x00, 0x01, 0x1A}. (with or without the leading 0x) I found several answers that claim to do this, but they all seem to convert to this {132, 0, 8, 26}...

I'm completely stuck...thanks in advance

3
  • 2
    {132, 0, 8, 26} is the decimal equivalent of {0x84, 0x00, 0x01, 0x1A}. Commented Apr 4, 2014 at 5:55
  • byte value does not have format assigned. It's just a value. How it's being displayed is up to either IDE (when you use debugger tools to peak the value during debugging) or use code, when it's transformed to string and shown to user. Commented Apr 4, 2014 at 5:55
  • ah yes...thank you! the serial protocol for my hardware shows hex so I figured it needed to be...I should have just tried decimal...because it works!. lesson learned, thanks again! Commented Apr 4, 2014 at 12:26

1 Answer 1

1

{132, 0, 8, 26} is the same as {0x84, 0x00, 0x08, 0x1A}, only in decimal notation.

132 == 0x84 (8*16^1 + 4*16^0 = 132 = 1*10^2 + 3*10^1 + 2*10^0)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.