start mod06 ex00

This commit is contained in:
hugogogo
2025-03-15 18:56:04 +01:00
parent bd23d89706
commit 4f18cd2c56
6 changed files with 20 additions and 138 deletions

View File

@@ -8,32 +8,9 @@ void int_to_hex_string(uint64_t value, char *out, uint8_t num_digits) { // nu
out[num_digits] = '\0';
}
void int_to_string(uint64_t value, char *buffer) {
// handle zero case
if (value == 0) {
buffer[0] = '0';
return;
}
uint8_t size = -1;
uint64_t copy = value;
while (copy) {
copy /= 10;
size++;
}
while (value) {
uint8_t digit = value % 10;
buffer[size] = digit + '0';
value /= 10;
size--;
}
}
void itoa_base(uint64_t value, char *buffer, uint8_t base) { // buffer must have the right size
void int_to_string_base(uint64_t value, char *buffer, uint8_t base) { // buffer must have the right size
if (base < 2 || base > 36) {
buffer[0] = '\0'; // unsupported base
buffer[0] = '\0'; // unsupported base
return;
}
@@ -52,8 +29,8 @@ void itoa_base(uint64_t value, char *buffer, uint8_t base) { // buffer must have
size++;
}
buffer[size] = '\0'; // null-terminate the string
size--; // adjust index for last digit
buffer[size] = '\0'; // null-terminate the string
size--; // adjust index for last digit
while (value) {
uint8_t digit = value % base;
@@ -61,4 +38,4 @@ void itoa_base(uint64_t value, char *buffer, uint8_t base) { // buffer must have
value /= base;
size--;
}
}
}