问题
Anyone have a code to convert char array to HEX? And return back to the actual results?
Because when I try to use this:
char data[]="hello word";
Serial.print(data,HEX);
then will give me an overload error.
回答1:
For brute force, you could try:
for (size_t i = 0; i < sizeof(data) - 1)
{
Serial.print(static_cast<unsigned int>(data[i]), HEX);
}
In the above snippet, each character is casted to an integer to get the internal representation value, then output.
There may be more efficient methods, but that is left to the OP to research.
来源:https://stackoverflow.com/questions/49135413/anyone-have-a-code-to-convert-char-array-to-hex-and-return-back-to-the-actual