我的双轨迹可能超过64个轨道/组合。 我想将其改为10基数,以便我能够将其产出到ole。
据我所知,C++没有支持任何超过64倍的分类账,但编辑特定类型除外。 因此,如果我希望以人类可读的形式将其产出到奥洛尔,那么我就需要将双轨座改成基10体(而不是基数10英寸)。
我有以下法典......
int char_to_int(const char c) {
return ((int) c) - 48;
}
std::string string_addition(std::string s1, std::string s2) {
std::string ret = "";
// making sure the two strings are the same length
while(s1.size() > s2.size())
s2 = 0 + s2;
while (s2.size() > s1.size())
s1 = 0 + s1;
// adding and carrying
for (int32_t i = (int32_t) s1.size(); i >= 0; i--)
ret[i] = (char) ((char_to_int(s1[i]) + char_to_int(s2[i])) + 48);
for (int32_t i = (int32_t) ret.size() - 1; i >= 0; i--)
...
// then finally returning
return ret
}
std::string to_base_ten(const std::string& s) {
std::string ret = "";
for (size_t i = 0; i < s.size(); i++) {
// for each digit, calculate the appropriate number to add
int64_t temp = s[i] * (int) std::pow(2, i);
// performing addition with strings because of potential integer overflow issues
ret = string_addition(ret, std::to_string(temp));
}
return ret;
}
...which just gets tedious and hard to read/understand because of converting with strings. Are there any simpler or more efficient ways of accomplishing this task?