Hex to char array in C

后端 未结 11 1148
广开言路
广开言路 2020-11-30 09:04

Given a string of hex values i.e. e.g. \"0011223344\" so that\'s 0x00, 0x11 etc.

How do I add these values to a char array?

Equivalent to say:

<
11条回答
  •  孤街浪徒
    2020-11-30 10:05

    Fatalfloor...

    There are a couple of ways to do this... first, you can use memcpy() to copy the exact representation into the char array.

    You can use bit shifting and bit masking techniques as well. I'm guessing this is what you need to do as it sounds like a homework problem.

    Lastly, you can use some fancy pointer indirection to copy the memory location you need.

    All of these methods are detailed here:

    Store an int in a char array?

提交回复
热议问题