update math to add convert int to string
This commit is contained in:
@@ -7,3 +7,26 @@ void int_to_hex_string(uint64_t value, char *out, uint8_t num_digits) { // nu
|
||||
}
|
||||
out[num_digits] = '\0';
|
||||
}
|
||||
|
||||
void uint16_to_string(uint16_t value, char buffer[17]) {
|
||||
// handle zero case
|
||||
if (value == 0) {
|
||||
buffer[0] = '0';
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t size = -1;
|
||||
uint16_t copy = value;
|
||||
|
||||
while (copy) {
|
||||
copy /= 10;
|
||||
size++;
|
||||
}
|
||||
|
||||
while (value) {
|
||||
uint8_t digit = value % 10;
|
||||
buffer[size] = digit + '0';
|
||||
value /= 10;
|
||||
size--;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user