Add itoa function

This commit is contained in:
logicog
2026-01-18 07:39:49 +01:00
parent d1d5d5e18f
commit e8a719d911
2 changed files with 17 additions and 0 deletions
+16
View File
@@ -172,6 +172,22 @@ void write_char(char c)
}
void itoa(uint8_t v)
{
uint8_t t = (v / 100);
// when print_zeros is not zero, we know that a non-zero number has printed.
// That have to print all the next numbers.
uint8_t print_zeros = t;
if (print_zeros)
write_char('0' + t);
t = (v / 10) % 10;
print_zeros |= t;
if (print_zeros)
write_char('0' + t);
write_char('0' + (v % 10));
}
void print_string(__code char *p)
{
while (*p)