From: Amelia Coutard Date: Sun, 26 Mar 2023 02:14:56 +0000 (+0200) Subject: Made ints print in base 10 X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=813f372dc4ff7850fbfe687faac6c8976226f327;p=voyage-au-centre-des-fichiers.git Made ints print in base 10 --- diff --git a/kernel/src/serial.cpp b/kernel/src/serial.cpp index bd70246..abc05e8 100644 --- a/kernel/src/serial.cpp +++ b/kernel/src/serial.cpp @@ -60,17 +60,18 @@ void os::print_formatted(const char* format, const char* val) { } void os::print_formatted(const char* format, std::uint64_t val) { os::assert(format[0] == '}', "Format string unsupported. TODO."); - bool printed = false; - os::print("0x"); - for (int i = 60; i >= 0; i -= 4) { - const int v = (val >> i) & 0xF; - if (printed || v != 0) { - os::printc(v < 10 ? v + '0' : v - 10 + 'a'); - printed = true; - } + char data[20]; + char* curr = data + 19; + while (val != 0) { + *curr = val % 10 + '0'; + val /= 10; + curr--; } - if (!printed) { + curr++; + if (curr == data + 20) { os::printc('0'); + } else while (curr < data + 20) { + os::printc(*curr++); } } void os::print_formatted(const char* format, std::int64_t val) {