How to `Serial.print()` “full” hexadecimal bytes?

前端 未结 6 1964
猫巷女王i
猫巷女王i 2021-01-18 02:17

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 u

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-18 03:20

    The lowest footprint in Memory, Code and runtime would be classic bit playing

    byte b;
    Serial.print(b>>4,  HEX);
    Serial.print(b&0x0F,HEX);
    

    Which is working fine on any 8bit type. For any other mask also the first line to

    Serial.print((b>>4)&0x0F,  HEX);
    

提交回复
热议问题