mpaymetov / oop-labs

Задания по объектно-ориентированному программированию
0 stars 0 forks source link

Замечания по Radix #10

Closed alexey-malov closed 5 years ago

alexey-malov commented 5 years ago
bool getRadix(const std::string& str, int& radix)
...
    int source_radix, destination_radix;
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
std::string IntToString(int n, int radix, bool & wasError)
{
    std::string numberStr = "";
    int number = n;
    int digit;
    std::string ch;
    bool isNegative = false;
    if (number < 0)
    {
        isNegative = true;
        number *= -1;
    }

    while(number != 0) 
    {
        digit = number % radix;
        if (digit > 9)
        {
            ch = 'A' + digit - 10;
        }
        else
        {
            ch = '0' + digit;
        }
        numberStr = ch + numberStr;
        number = (number - digit) / radix;
    }

    if (isNegative)
    {
        numberStr = '-' + numberStr;
    }
    return numberStr;
}
alexey-malov commented 5 years ago
std::string IntToString(unsigned int number, unsigned int radix, bool & isNegative, bool & wasError)