Add simple itoa-style function

This commit is contained in:
Stefan `Sec` Zehl 2011-07-27 23:41:09 +02:00
parent 932d5502d2
commit 5e1ac514ea
3 changed files with 19 additions and 1 deletions

View File

@ -19,6 +19,7 @@ OBJS += byteorder.o
OBJS += random.o OBJS += random.o
OBJS += idle.o OBJS += idle.o
OBJS += config.o OBJS += config.o
OBJS += itoa.o
LIBNAME=basic LIBNAME=basic

View File

@ -203,5 +203,7 @@ int applyConfig(void);
#define SYSTICKSPEED 10 #define SYSTICKSPEED 10
#endif // itoa.c
const char* IntToStrX(unsigned int num, unsigned int mxlen);
#endif

15
firmware/basic/itoa.c Normal file
View File

@ -0,0 +1,15 @@
#define LEN 32
const char* IntToStrX(unsigned int num, unsigned int mxlen){
static char s[LEN+1];
char * o=s;
int len;
s[LEN]=0;
for (len=(LEN-1);len>=(LEN-mxlen);len--){
s[len]=(num%16)+'0';
if(s[len]>'9')
s[len]+='A'-'9'-1;
num/=16;
};
return &s[len+1];
};