This commit is contained in:
Jonathan Turner 2023-11-29 09:58:22 -05:00
parent af3dd999e2
commit b04f95d41f
2 changed files with 17 additions and 3 deletions

View File

@ -39,8 +39,8 @@
if (sstrlen(input, 15) > 4) { if (sstrlen(input, 15) > 4) {
char *number = input + 4; char *number = input + 4;
u32 result = digit_conver(number); u32 result = digit_conver(number);
int nDigits = floor(log10(abs(result))) + 1; int nDigits = digit_len(result);
if (sstrlen(*number, 15) > nDigits + 4) { if (sstrlen(number, 15) > nDigits + 4) {
kprint("There is a limit"); kprint("There is a limit");
} }
if (result < 10000) { 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) { int digit_conver(const char *hexString) {
u32 result = 0; u32 result = 0;
while (*hexString != '\0') { while (*hexString != '\0') {

View File

@ -10,7 +10,7 @@
#include "../libc/linked.h" #include "../libc/linked.h"
void user_input(char *input); void user_input(char *input);
int digit_len(unsigned digit);
int digit_conver(const char *str); int digit_conver(const char *str);
#endif #endif