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:
commit
c94d5922e0
1 changed files with 10 additions and 10 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue