Skip to content

Instantly share code, notes, and snippets.

@bootrino
Created February 10, 2019 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bootrino/06b821fb65b7aaad020c3ba532097a4c to your computer and use it in GitHub Desktop.
Save bootrino/06b821fb65b7aaad020c3ba532097a4c to your computer and use it in GitHub Desktop.
Print uint32_t as hex in Arduino
unsigned char bytes[4];
bytes[0] = (u32 >> 24) & 0xFF;
bytes[1] = (u32 >> 16) & 0xFF;
bytes[2] = (u32 >> 8) & 0xFF;
bytes[3] = u32 & 0xFF;
for(int i = 0; i < 4; i++)
{
if (i == 0) Serial.print("0x");
Serial.print(bytes[i], HEX);
if (i < 3) Serial.print(":");
if (i == 3) Serial.print("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment