如何在 Arduino 中将 64 位 uint64_t 打印为十六个十六进制数字
使用 Arduino 时,你经常想打印 64 位值(如 uint64_t)的十六进制值,由十六个十六进制数字组成。例如,如果你有 uint64_t val = 169557370125;,你打算打印 000000277a68250d。
在 Arduino 中,你可以使用 Serial.printf() 以 %08lx08lx 作为格式说明符来实现,将 uint64_t 拆分为两个 uint32_t 实例并一个接一个地打印:
print_uint64_hex.ino
Serial.printf("%08lx%08lx\r\n",
((uint32_t)((val >> 32) & 0xFFFFFFFF)),
((uint32_t)(val & 0xFFFFFFFF)));有关 %x 含义以及为什么我们需要在 %08x 中使用 08 作为 printf 格式说明符的更多信息,请参见如何在 Arduino 中将 32 位 uint32_t 打印为八个十六进制数字。
Check out similar posts by category:
Arduino, Electronics, Embedded, PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow