

/*give integer as input get a string as output. 
returned strlen is fixed,=5*/
char* tostr(unsigned int num)
{
	unsigned int base;
	unsigned char rem,x;
	char buff[6];
	char *ptr=buff;
	for(x=4;x>0;--x)
	{
		base=rpt(10,x);
				
		rem=num/base;
		
		*ptr=(char)rem+0x30;
		num-=rem*base;
		ptr++;
	 }
	 *ptr=(char)num+0x30;
	 buff[6]=' ';
	 return buff;
}


/* function used for generating
10000, 1000, 100, 10 successively
must be used in conjuction with 
tostr function*/
unsigned int rpt(unsigned int x,unsigned char y)
{
	unsigned char i;
	unsigned int temp=1;
	for(i=1;i<=y;i++)
	temp*=x;
	return temp;
}


/*give string as input
string will have 5 charaters
get the string with leading zeros blanked
returned strlen is constant and =5*/
char* rippleinsert(char* str)
{
	unsigned char i=0;
	while((*str==(char)0x30))
	{
		*str=(char)' ';
		str++;i++;
	 }
return(str-i);
} 


/*str= 5 byte wide string given as input
pos=number of positions required from lsb
eg: str=01000, pos=4, returns=1000
eg: str=23456, pos=2, returns=56
same as rippleinsert
but we can specify the string length*/

char* ripplepos(char *str,unsigned char pos)
{
	pos=5-pos;
	while(pos--) str++;
	return str;
}