It will misbehave if input contains an odd number of characters, and it doesn't deal particularly gracefully with non-hexadecimal characters, either. Usage: Bin2Text -c Count -h -s Skip Input Output Options: -c Number of bytes to convert to text Count Number of bytes to convert, -1 goes to end of file -h Display Usage Information (This screen) -s Skip the first number of bytes in the input file Skip Number of bytes to skip Arguments: Input File to read. I also tested it with a longer input string: input = "0102034a4b4c" This uses sscanf to convert the input string to hexadecimal, two characters (two hexadecimal digits, or one output byte) at a time. ![]() 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 |