This commit is contained in:
Aurora 2016-10-22 18:00:58 +02:00
parent 211cd964d7
commit 3fd783cd01

View File

@ -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--;
out[digits - 1 - i] = '0' + number % 10;
number /= 10;
}
number -= tmp * tmp2;
}
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;
}