Anyone have a code to convert char array to HEX ? And return back to the actual results?

做~自己de王妃 提交于 2020-01-06 06:01:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!