MNRS-BM-BSP/libwrap/misc/write_hex.c

18 lines
395 B
C
Raw Normal View History

2020-06-18 12:15:52 +02:00
/* See LICENSE of license details. */
#include <stdint.h>
#include <unistd.h>
2025-01-06 20:45:20 +01:00
void write_hex(int fd, uint32_t hex) {
2020-06-18 12:15:52 +02:00
uint8_t ii;
uint8_t jj;
char towrite;
2025-01-06 20:45:20 +01:00
write(fd, "0x", 2);
for (ii = 8; ii > 0; ii--) {
2020-06-18 12:15:52 +02:00
jj = ii - 1;
2025-01-06 20:45:20 +01:00
uint8_t digit = ((hex & (0xF << (jj * 4))) >> (jj * 4));
towrite = digit < 0xA ? ('0' + digit) : ('A' + (digit - 0xA));
2020-06-18 12:15:52 +02:00
write(fd, &towrite, 1);
}
}