Q:

Dividing bigint presented in string to 2

I am writting an function that divides a Big Int (128 bit) number presented in String by 2.
Ex: 8113 is  a string ="8113"
I know my function errors in the case du != 0. When i fix the code for an input, other input make errors.
Please give me some advice for my solution. If my algorithm is so bad, tell me the better then i can change my function in another way.
int CTOI(char a)
{
    return a - 48;
}

char ITOC(int a)
{
    if (a == 0)
        return '0';
    return a + '0';
}

int creDec(int a, int b)
{
    return (a * 10) + b;
}

string divide2(string str)
{
    string temp = str, t2;
    int du, kq;
    du = CTOI(temp[0]);
    if (du == 1) {
        temp.erase(0, 1);
        while (temp[0] != 0)
        {
            du = creDec(du, CTOI(temp[0]));
            if (du == 1)
            {
                temp.erase(0, 1);
            }
            else
                temp.erase(0, 1);
            kq = du / 2;
            t2 += ITOC(kq);
            du = du - kq * 2;
        }
    }
    else
    {
        while (temp[0] != 0)
        {
            if (du == 1)
            {
                temp.erase(0, 1);
                du = creDec(du, CTOI(temp[0]));
            }
            kq = du / 2;
            t2 += ITOC(kq);
            du = du - kq * 2;
            temp.erase(0, 1);
            du = creDec(du, CTOI(temp[0]));
        }

    }
    return t2;
}

A:

You seem to have added a lot of unnecessary complexity to the function. Here's a simplified function that works for me with my test cases.
string divide2(string str)
{
   string ret;  // Object to be returned.
   int rem = 0; // Keep track of remainders.

   // Iterate over the characters of the input string.
   auto iter = str.begin();
   auto end = str.end();
   for ( ; iter != end; ++iter )
   {
      int n1 = CTOI(*iter);     // The number from the string.
      int n2 = creDec(rem, n1); // The number after we account for the remainder.
      int n3 = n2/2;            // Result of the division.
      rem = n2%2;               // Remainder of the division.

      if ( ret.empty() && n3 == 0 )
      {
         // Do nothing. There is no need to addd leading zeros to ret.
      }
      else
      {
         // Add the character corresponding to n3 to ret.
         ret.push_back(ITOC(n3));
      }
   }

   // If the return value is an empty string, return "0".
   if ( ret.empty() )
   {
      return "0";
   }
   else
   {
      return ret;
   }
}

Working example.
It's better still to use a range-for loop to iterate over the characters of the string.
   for ( char ch : str )
   {
      int n1 = CTOI(ch);     // The number from the string.

       ...

