How to print 64-bit uint64_t as sixteen hex digits in Arduino
When using Arduino, you often want to print the hex value of a 64-bit value such as a uint64_t
, consisting of sixteen hex digits. For example, if you have uint64_t val = 169557370125;
, you intend to print 000000277a68250d
.
In Arduino you can do that using Serial.printf()
with %08lx08lx
as format specifier, splitting the uint64_t
in two uint32_t
instances and printing those one after another:
Serial.printf("%08lx%08lx\r\n",
((uint32_t)((val >> 32) & 0xFFFFFFFF)),
((uint32_t)(val & 0xFFFFFFFF)));
See How to print 32-bit uint32_t as eight hex digits in Arduino for more information on what %x
means and why we need to use the 08
in %08x
as a printf
format specifier.