0

I'm trying to build a char array that contains hex bytes on the fly.

I effectively want to create:

unsigned char myHexArray[] = { 0xfc, 0x48, 0x83, 0xe4, 0xf0, 0xe8...);

But I want to create it from a string like so:

std::string str = "fc4883e4f0e8...";

I usually write code in C#, although now I realise that's not really writing code!

I'd really appreciate some help here.

Thanks,

Mike

Mike
  • 61
  • 5
  • 1
    What are "hex bytes"? That's just a different way to write an integer or a char in your case. Can you please clarify input and expected output? The second example looks like you actually want to parse hex numbers from a string and turn them into characters or numbers. But it's not really clear, at least to me. – Lukas-T Sep 02 '21 at 09:33
  • yeah, sorry, I think part of my problem is terminology. So I want to take the first two chars from str "fc", and pass them in to the first index of myHexArray = so myHexArray[0] = 0xfc; – Mike Sep 02 '21 at 09:36
  • 1
    @Mike Try this: https://godbolt.org/z/hdvGx6PMY – m88 Sep 02 '21 at 10:36
  • All writing of code is *really* writing code. The language is 100% irrelevant. – molbdnilo Sep 02 '21 at 11:17
  • @molbdnilo - thanks for clearing that up. It was a flippant joke... – Mike Sep 04 '21 at 11:10

0 Answers0