diff --git a/Part3/09_memory/kernel/kernel.c b/Part3/09_memory/kernel/kernel.c index e78ea74..2c0a99e 100644 --- a/Part3/09_memory/kernel/kernel.c +++ b/Part3/09_memory/kernel/kernel.c @@ -39,8 +39,8 @@ if (sstrlen(input, 15) > 4) { char *number = input + 4; u32 result = digit_conver(number); - int nDigits = floor(log10(abs(result))) + 1; - if (sstrlen(*number, 15) > nDigits + 4) { + int nDigits = digit_len(result); + if (sstrlen(number, 15) > nDigits + 4) { kprint("There is a limit"); } if (result < 10000) { @@ -116,6 +116,20 @@ } + int digit_len(unsigned digit) { + if (x >= 1000000000) return 10; + if (x >= 100000000) return 9; + if (x >= 10000000) return 8; + if (x >= 1000000) return 7; + if (x >= 100000) return 6; + if (x >= 10000) return 5; + if (x >= 1000) return 4; + if (x >= 100) return 3; + if (x >= 10) return 2; + return 1; + } + + int digit_conver(const char *hexString) { u32 result = 0; while (*hexString != '\0') { diff --git a/Part3/09_memory/kernel/kernel.h b/Part3/09_memory/kernel/kernel.h index 9bcb437..390b86c 100644 --- a/Part3/09_memory/kernel/kernel.h +++ b/Part3/09_memory/kernel/kernel.h @@ -10,7 +10,7 @@ #include "../libc/linked.h" void user_input(char *input); - +int digit_len(unsigned digit); int digit_conver(const char *str); #endif