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:
char array[4] = { 0x00, 0x11 ... };
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:
char array[4] = { 0x00, 0x11 ... };
Give a best way:
Hex string to numeric value , i.e. str[] = "0011223344" to value 0x0011223344, use
done. if need remove beginning 0x00, see below.
though for LITTLE_ENDIAN platforms, plus: Hex value to char array, value 0x11223344 to char arr[N] = {0x00, 0x11, ...}
done.
Notes: For converting long string to a 64 bits hex char arr on a 32-bit system, you should use unsigned long long instead of unsigned long, and htonl is not enough, so do it yourself as below because might there's no htonll, htonq or hton64 etc:
see http://effocore.googlecode.com/svn/trunk/devel/effo/codebase/builtin/include/impl/sys/bswap.h
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?
I was searching for the same thing and after reading a lot, finally created this function. Thought it might help, someone