/***********************************************/
/* */
/* 将无符号整型值的每一位转化为字符并打印它 */
/* xwlee 2006/12/4 */
/***********************************************/
#include <stdio.h>
#include <time.h>
void binary_to_ascii(unsigned int value);
int main()
{
int i;
unsigned int my_bin;
srand( (unsigned)time( NULL ) );
for(i=0; i<24; ++i)
{
my_bin = rand() % 5000;
printf("%2d. my_bin=%4d,exchange ascii is: ",i+1,my_bin);
binary_to_ascii(my_bin);
printf("/n");
}
getch();
return 0;
}
void binary_to_ascii(unsigned int value)
{
unsigned int quotient;
quotient = value /10;
if(quotient != 0)
binary_to_ascii(quotient);
putchar(' ');
putchar(value % 10 + '0');
}
本文介绍了一个简单的C语言程序,该程序能够将无符号整数的每一位转换为对应的ASCII字符,并将其打印出来。通过递归的方式实现了从高位到低位的逐位转换。
994

被折叠的 条评论
为什么被折叠?



