![]() ![]() ![]() It will misbehave if input contains an odd number of characters, and it doesn't deal particularly gracefully with non-hexadecimal characters, either. I also tested it with a longer input string: input = "0102034a4b4c" It also includes a declaration of the length of the array. You can dump that into a file to be included, and then just access foo like any other character array (or link it in). This uses sscanf to convert the input string to hexadecimal, two characters (two hexadecimal digits, or one output byte) at a time. A complete static array definition is written (named after the input file), unless xxd reads from stdin. To get the hex-to-binary conversion you want, while avoiding byte order issues and anticipating the possibility of an arbitrary-length input string, you can do this one byte at a time with code like this: char *p Your sprintf call created the string \x46abĪnd you wrote those six characters to the file without further interpretation, so that's what you saw in the file (hex bytes 5c 78 34 36 61 62). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |