[*C*]将整数转化为十进制字符串的函数Convert integer to Decimal string

程序代码

/*
  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
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值