任何人都有将 char 数组转换为 HEX 的代码?并返回到实际结果? [英] Anyone have a code to convert char array to HEX ? And return back to the actual results?

查看:15
本文介绍了任何人都有将 char 数组转换为 HEX 的代码?并返回到实际结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人有将字符数组转换为十六进制的代码吗?并返回到实际结果?

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.

推荐答案

对于蛮力,您可以尝试:

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.

可能有更有效的方法,但这留给 OP 研究.

There may be more efficient methods, but that is left to the OP to research.

这篇关于任何人都有将 char 数组转换为 HEX 的代码?并返回到实际结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆