func.c
来自「C8051F120 _AD开发过程中的一些代码和文档」· C语言 代码 · 共 63 行
C
63 行
#include "Func.h"
char* itoa(unsigned int value, char* buf,unsigned char radix)
{
unsigned int i;
char* ptr;
char* temphold;
temphold = buf;
ptr = buf + 12;
*--ptr = 0; // Insert NULL char
do
{
// First create string in reverse order
i = (value % radix) + 0x30;
if(i > 0x39)
{
i += 7;
}
*--ptr = i;
value = value / radix;
} while(value != 0);
// Next, move the string 6 places to the left
// Include NULL character
for( ; (*buf++ = *ptr++); )
{
;
}
return(temphold);
}
char* ltoa(unsigned long value, char* buf,unsigned char radix)
{
unsigned char i;
char* ptr;
char* temphold;
temphold = buf;
ptr = buf + 12;
*--ptr = 0; // Insert NULL char
do
{
// First create string in reverse order
i = (value % radix) + 0x30;
if(i > 0x39)
{
i += 7;
}
*--ptr = i;
value = value / radix;
} while(value != 0);
// Next, move the string 6 places to the left
// Include NULL character
for( ; (*buf++ = *ptr++); )
{
;
}
return(temphold);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?