コード例 #1
0
ファイル: BaseConverter.cpp プロジェクト: bartop/CompleteMath
unsigned int BaseConverter::divide(const std::string& baseDigits, std::string& x, unsigned int y)
{
	std::string quotient { };

    size_t lenght = x.length();
    for (size_t i = 0; i < lenght; ++i)
    {
        size_t j = i + 1 + x.length() - lenght;
        if (x.length() < j)
            break;

        unsigned int value = base2dec(baseDigits, x.substr(0, j));

        quotient.push_back(baseDigits[value / y]);
        x = dec2base(baseDigits, value % y) + x.substr(j);
    }

    // calculate remainder
    unsigned int remainder = base2dec(baseDigits, x);

    // remove leading "zeros" from quotient and store in 'x'
    size_t n = quotient.find_first_not_of(baseDigits[0]);
    if (n != std::string::npos)
    {
        x = quotient.substr(n);
    }
    else
    {
        x.clear();
    }

    return remainder;
}
コード例 #2
0
char *bin2dec(char *str)
{
  return base2dec(str, 2);
}
コード例 #3
0
ファイル: BaseConverter.cpp プロジェクト: bartop/CompleteMath
unsigned int BaseConverter::toDecimal(std::string value) const
{
    return base2dec(sourceBaseSet_, value);
}