From 3fd783cd01633a0eb4bec9165fde797110810473 Mon Sep 17 00:00:00 2001 From: Aurora Date: Sat, 22 Oct 2016 18:00:58 +0200 Subject: [PATCH] Cleanup --- source/strings.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/source/strings.c b/source/strings.c index bb704bf..e135955 100644 --- a/source/strings.c +++ b/source/strings.c @@ -43,11 +43,11 @@ void concatenateStrings(char *destination, const char *source) void hexItoa(u32 number, char *out, u32 digits, bool fillString) { const char hexDigits[] = "0123456789ABCDEF"; - u32 i = 0; + u32 i; - while(number > 0) + for(i = 0; number > 0; i++) { - out[digits - 1 - i++] = hexDigits[number & 0xF]; + out[digits - 1 - i] = hexDigits[number & 0xF]; number >>= 4; } @@ -56,27 +56,11 @@ void hexItoa(u32 number, char *out, u32 digits, bool fillString) void decItoa(u32 number, char *out, u32 digits) { - while(number >= 10) + for(u32 i = 0; number > 0; i++) { - u32 i, - tmp; - - for(i = 0, tmp = number; tmp >= 10; tmp /= 10, i++); - - out[digits - 1 - i] = '0' + tmp; - - u32 tmp2 = 10; - - while(i > 1) - { - tmp2 *= 10; - i--; - } - - number -= tmp * tmp2; + out[digits - 1 - i] = '0' + number % 10; + number /= 10; } - - out[digits - 1] = '0' + number; } u32 hexAtoi(const char *in, u32 digits) @@ -85,10 +69,7 @@ u32 hexAtoi(const char *in, u32 digits) char *tmp = (char *)in; for(u32 i = 0; i < digits && *tmp != 0; tmp++, i++) - { - res <<= 4; - res += *tmp > '9' ? *tmp - 'A' + 10 : *tmp - '0'; - } + res = (*tmp > '9' ? *tmp - 'A' + 10 : *tmp - '0') + (res << 4); return res; }