Answer the question
In order to leave comments, you need to log in
How to convert a string containing hex to native hex in C++?
In an Arduino project, I needed to assemble a hexadecimal command for an external device using string concatenation. How to convert a string like "0x0104" to like -- 0x0104 (number)? I have no experience in low-level programming, so I'm wandering around.
Answer the question
In order to leave comments, you need to log in
Drop 0x, then loop through the line from left to right. Each character is translated into the corresponding number, let it be h. Then result = result | h; result = result << 8; and move to the next character.
Translation from character to number - 2-3 IF.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question