Use more readable byte access patterns (compiles the same)

This commit is contained in:
Allen Hill
2026-05-15 22:20:06 +00:00
parent 99ca75ce45
commit 194c3928f9
2 changed files with 18 additions and 18 deletions
+6 -6
View File
@@ -96,20 +96,20 @@ void RS232_PrintHex8(uint8_t Data) {
}
void RS232_PrintHex12(uint16_t x) {
RS232_PrintHex4(*(((uint8_t *)&x) + 1));
RS232_PrintHex8(*(((uint8_t *)&x) + 0));
RS232_PrintHex4((uint8_t)(x >> 8));
RS232_PrintHex8((uint8_t)x);
}
void RS232_PrintHex(uint16_t x) {
if (x > 0x0fff) {
RS232_PrintHex8(*(((uint8_t *)&x) + 1));
RS232_PrintHex8((uint8_t)(x >> 8));
} else if (x > 0xff) {
RS232_PrintHex4(*(((uint8_t *)&x) + 1));
RS232_PrintHex4((uint8_t)(x >> 8));
}
if (x > 0x0f) {
RS232_PrintHex8(*(((uint8_t *)&x) + 0));
RS232_PrintHex8((uint8_t)x);
} else {
RS232_PrintHex4(*(((uint8_t *)&x) + 0));
RS232_PrintHex4((uint8_t)x);
}
}