Is there any standard C function that converts from hexadecimal string to byte array?
I do not want to write my own function.
Is there any standard C function that converts from hexadecimal string to byte array
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As far as I know, there’s no standard function to do so, but it’s simple to achieve in the following manner:
Edit
As Al pointed out, in case of an odd number of hex digits in the string, you have to make sure you prefix it with a starting 0. For example, the string
"f00f5"will be evaluated as{0xf0, 0x0f, 0x05}erroneously by the above example, instead of the proper{0x0f, 0x00, 0xf5}.Amended the example a little bit to address the comment from @MassimoCallegari