You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
554 B
33 lines
554 B
/* |
|
* Copyright (c) 2019 Oticon A/S |
|
* |
|
* SPDX-License-Identifier: Apache-2.0 |
|
*/ |
|
|
|
#include <zephyr/sys/util.h> |
|
|
|
uint8_t u8_to_dec(char *buf, uint8_t buflen, uint8_t value) |
|
{ |
|
uint8_t divisor = 100; |
|
uint8_t num_digits = 0; |
|
uint8_t digit; |
|
|
|
while ((buflen > 0) && (divisor > 0)) { |
|
digit = value / divisor; |
|
if ((digit != 0) || (divisor == 1) || (num_digits != 0)) { |
|
*buf = digit + (char)'0'; |
|
buf++; |
|
buflen--; |
|
num_digits++; |
|
} |
|
|
|
value -= digit * divisor; |
|
divisor /= 10; |
|
} |
|
|
|
if (buflen != 0) { |
|
*buf = '\0'; |
|
} |
|
|
|
return num_digits; |
|
}
|
|
|