/*
Convert a integer to a Decimal string,when the number is not enough five digitals,the string will align to left
For instance,use the number 817 as parameter,will return "817",without '0' filling.
Argument(s):unsigned int IntNum,the number will be convert.
Return value:the pointer of the string.
*/
const unsigned char HEXCODE[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
unsigned char *IntegertoDecimalString(unsigned int IntNum)
{
unsigned char *Ptem="\0\0\0\0\0";
//First,check how many figures the number is.
unsigned char Weight;
unsigned int temNum=IntNum;
while(temNum!=0)
{
Weight++;
temNum/=10;
}
//Convert the digitals to characters,acodding the figures of the number
temNum=IntNum;
Ptem[Weight]=0;//Add a null character
while(Weight!=0)
{
Ptem[--Weight]=HEXCODE[temNum%10];
temNum/=10;
}
return Ptem;//return the point of string
}
[*C*]将整数转化为十进制字符串的函数Convert integer to Decimal string
最新推荐文章于 2022-06-17 17:42:16 发布
程序代码