0

Let's say I have a string that is actually bytecode

"90B482"

I need to convert this into an array of char in the following style:

unsigned char converted = { '\x90', '\xB4', '\x82' };

This is going to be consistently calculating, so I need an efficient way to do this, but the only way I have been able to come up with in terms of solving this is writing a massive parsing function

w0f
  • 908
  • 9
  • 23
  • A simple loop, a few comparisons, and a few arithmetical operations, does not make for a "massive parsing function". Various C and C++ libraries have been doing this kind of conversion, efficiently, for decades now. It helps if, you know, understand the ASCII character set, and how to trivially convert hexadecimal ASCII characters. – Sam Varshavchik Mar 04 '17 at 03:15
  • Have you tried `atoi` and then using right shifts? You could find better solutions, like Sam pointed out correctly, however this is a rather easy solution. – adentinger Mar 04 '17 at 03:15

0 Answers0