HEX assignement in C
c, c++
Solution
I don't think there's a way to make a literal out of it.
You can parse the string at runtime and store it in another array.
You can use sed or something to rewrite the sequence:
echo 401DA1815EB560399FE365DA23AAC0757F1D61EC10839D9B5521F | sed -e 's/../\\x&/g'
\x40\x1D\xA1\x81\x5E\xB5\x60\x39\x9F\xE3\x65\xDA\x23\xAA\xC0\x75\x7F\x1D\x61\xEC\x10\x83\x9D\x9B\x55\x21F
Problem
I have generated a long sequence of bytes which looks as follows: ``` 0x401DA1815EB560399FE365DA23AAC0757F1D61EC10839D9B5521F..... ``` Now, I would like to assign it to a static unsigned char x[]. Obviously, I get the warning that hex escape sequence out of range when I do this here ``` static unsigned char x[] = "\x401DA1815EB56039....."; ``` The format it needs is ``` static unsigned char x[] = "\x40\x1D\xA1\x81\x5E\xB5\x60\x39....."; ``` So I am wondering if in C there is a way for this assignment without me adding the hex escape sequence after each byte (could take quite a while)