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

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. Commented Sep 2, 2021 at 9: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; Commented Sep 2, 2021 at 9:36
  • 1
    @Mike Try this: godbolt.org/z/hdvGx6PMY Commented Sep 2, 2021 at 10:36
  • All writing of code is really writing code. The language is 100% irrelevant. Commented Sep 2, 2021 at 11:17
  • @molbdnilo - thanks for clearing that up. It was a flippant joke... Commented Sep 4, 2021 at 11:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.