I am programming Arduino and I am trying to Serial.print()
bytes in hexadecimal format "the my way" (keep reading for more information).
That is, by using the following code
byte byte1 = 0xA2;
byte byte2 = 0x05;
byte byte3 = 0x00;
Serial.println(byte1, HEX);
Serial.println(byte2, HEX);
Serial.println(byte3, HEX);
I get the following output in the Serial Monitor:
A2
5
0
However I would like to output the following:
A2
05
00
In words, I would like to print the "full" hexadecimal value including 0
s (05
instead of 0
and 00
instead of 0
).
How can I make that?
sprintf(buffer, "%02x", number); Serial.println(buffer);
– Alexandriaalexandriansprintf
. – Glotticsprintf
seems to be supported by Arduino. – Eaglewood0xFA2
, you will need to also print005
and000
? – Dampen0xFA2
byte exists? – Eaglewood