Add simple itoa-style function
This commit is contained in:
parent
932d5502d2
commit
5e1ac514ea
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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];
|
||||||
|
};
|
Loading…
Reference in New Issue