1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 13:25:30 +03:00

Merge pull request #1593 from AndersHoglund/typeconversions

Another try in cleaning up typeconversions
This commit is contained in:
Michael Keller 2016-11-18 13:50:03 +13:00 committed by GitHub
commit c94d5922e0

View file

@ -24,18 +24,18 @@
void uli2a(unsigned long int num, unsigned int base, int uc, char *bf) void uli2a(unsigned long int num, unsigned int base, int uc, char *bf)
{ {
int n = 0;
unsigned int d = 1; unsigned int d = 1;
while (num / d >= base) while (num / d >= base)
d *= base; d *= base;
while (d != 0) { while (d != 0) {
int dgt = num / d; int dgt = num / d;
*bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10);
// Next digit
num %= d; num %= d;
d /= base; d /= base;
if (n || dgt > 0 || d == 0) {
*bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10);
++n;
}
} }
*bf = 0; *bf = 0;
} }
@ -53,18 +53,18 @@ void li2a(long num, char *bf)
void ui2a(unsigned int num, unsigned int base, int uc, char *bf) void ui2a(unsigned int num, unsigned int base, int uc, char *bf)
{ {
int n = 0;
unsigned int d = 1; unsigned int d = 1;
while (num / d >= base) while (num / d >= base)
d *= base; d *= base;
while (d != 0) { while (d != 0) {
int dgt = num / d; int dgt = num / d;
*bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10);
// Next digit
num %= d; num %= d;
d /= base; d /= base;
if (n || dgt > 0 || d == 0) {
*bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10);
++n;
}
} }
*bf = 0; *bf = 0;
} }