void divide_by_2 (bigint::bigvalue_t& div_by) { //int data = 0; begin/rend 000001 end/rbegin == 100000 for(unsigned it = 0; it < div_by.size(); ++it) { // Divide the value at index it by 2 div_by.at(it) /= 2; // If the next higher digit is odd, add 5 to current digit if(it < div_by.size() - 1) { if(div_by.at(it + 1) % 2) { div_by.at(it) += 5; } } } div_by = trim(div_by); }
bigint::bigvalue_t do_bigmult(const bigint::bigvalue_t& left, const bigint::bigvalue_t& right) { bigint::bigvalue_t prod; prod.resize(left.size() + right.size()); int carry = 0; int d = 0; int uv = 0; for(unsigned i = 0; i != left.size(); ++i) { carry = 0; for(unsigned j = 0; j != right.size(); ++j) { uv = left.at(i) * right.at(j); d = prod.at(i + j) + uv + carry; prod.at(i + j) = d % 10; carry = d/10; } if(carry != 0) { prod.at(right.size() + i) = carry; } } prod = trim(prod); return prod; }