2025-06-08 05:27:41 +00:00
|
|
|
#include "kttools.h"
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
/*
|
|
|
|
|
* VARS
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//Placeholder.
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* FUNCTIONS
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-07-05 08:36:39 +00:00
|
|
|
void i_to_str(uint64_t num, char* buf, int size, int radix) {
|
2025-06-08 05:27:41 +00:00
|
|
|
//null terminate the string
|
2025-06-28 04:14:42 +00:00
|
|
|
if(num == 0){
|
|
|
|
|
buf[0] = '0';
|
|
|
|
|
buf[1] = '\0';
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-06-08 05:27:41 +00:00
|
|
|
buf[--size] = '\0';
|
|
|
|
|
while(size > 0 && (num) != 0){
|
2025-06-08 20:18:06 +00:00
|
|
|
int isolated_num = num % radix;
|
2025-06-08 05:27:41 +00:00
|
|
|
if(isolated_num > 9){
|
|
|
|
|
isolated_num+=7;
|
|
|
|
|
}
|
|
|
|
|
buf[--size] = '0' + isolated_num;
|
2025-06-08 20:18:06 +00:00
|
|
|
num/=radix;
|
2025-06-08 05:27:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//now shift the whole thing to the left
|
|
|
|
|
if(size != 0) {
|
|
|
|
|
while(buf[size]!='\0') {
|
|
|
|
|
*buf = buf[size];
|
|
|
|
|
buf++;
|
|
|
|
|
}
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|