如何在 Arduino 中将字符串打印为十六进制字节序列
以下代码将 std::string 打印到 Serial 作为十六进制字符序列。它可以轻松地适配以与其他类型的字符串一起工作。
print_string_hex_arduino.cpp
const char* cstr = str.c_str();
for (size_t i = 0; i < str.size(); i++)
{
Serial.printf("%02X ", cstr[i]);
}此代码基于我们之前的文章如何在 Arduino 中将字节打印为两个十六进制数字
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow