Printf now has long (64-bit), char, and % literal support. I haven't written anything specific for shorts yet but if you cast it to an int on the way in, it'll work anyway, so whatever.
41 lines
700 B
C
41 lines
700 B
C
#include "kttools.h"
|
|
#include <stdint.h>
|
|
/*
|
|
* VARS
|
|
*/
|
|
|
|
//Placeholder.
|
|
|
|
/*
|
|
* FUNCTIONS
|
|
*/
|
|
|
|
|
|
|
|
void i_to_str(uint64_t num, char* buf, int size, int radix) {
|
|
//null terminate the string
|
|
if(num == 0){
|
|
buf[0] = '0';
|
|
buf[1] = '\0';
|
|
return;
|
|
}
|
|
buf[--size] = '\0';
|
|
while(size > 0 && (num) != 0){
|
|
int isolated_num = num % radix;
|
|
if(isolated_num > 9){
|
|
isolated_num+=7;
|
|
}
|
|
buf[--size] = '0' + isolated_num;
|
|
num/=radix;
|
|
}
|
|
|
|
//now shift the whole thing to the left
|
|
if(size != 0) {
|
|
while(buf[size]!='\0') {
|
|
*buf = buf[size];
|
|
buf++;
|
|
}
|
|
*buf = '\0';
|
|
}
|
|
}
|
|
|