现在的位置: 首页 > 综合 > 正文

将无符号整型值的每一位转化为字符并打印它

2013年08月03日 ⁄ 综合 ⁄ 共 726字 ⁄ 字号 评论关闭

/***********************************************/
/*                                             */
/*   将无符号整型值的每一位转化为字符并打印它  */
/*             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');

抱歉!评论已关闭.