Chinaunix首页 | 论坛 | 博客
  • 博客访问: 212774
  • 博文数量: 70
  • 博客积分: 2050
  • 博客等级: 大尉
  • 技术积分: 700
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-15 21:42
文章分类

全部博文(70)

文章存档

2013年(1)

2011年(5)

2010年(3)

2009年(9)

2008年(17)

2007年(6)

2006年(29)

我的朋友

分类: C/C++

2006-08-04 14:06:26

/**
 * base conversion
 * \param output bignum output
 * \param input bignum input
 * \param length length of input bignum
 * \param ibase input base, must between 2..256
 * \param obase output base, must between 2..256
 * \return length of bignum in output
 * \warning contents of ``input'' will be changed during conversion
 */

int
bconv(unsigned char *outputunsigned char *inputint lengthint ibaseint obase)
{
    unsigned int rcdivisor;
    unsigned char *pc;

    p = output;
    while (length > 0)
    {
        while (input[0] == 0 && length > 0 && ++input)
            --length;
        if (length)
        {
            divisor = 0;
            for (rc = 0rc < length; ++rc)
            {
                divisor *= ibase;
                divisor += input[rc];
                input[rc] = divisor / obase;
                divisor %= obase;
            }
            *p++ = divisor;
        }
    }
    rc = p - output;
    while (--p > output)
    {
        c = *p;
        *p = *output;
        *output = c;
        ++output;
    }

    return rc;
}
阅读(1092) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~