#include #include "Trinary.h" using namespace std; string IntToTrinary(int number){ string value; int digit; bool negative{false}; if (number < 0) { number *= -1; negative = true; } if (number == 0) { value = "0"; } while(number > 0) { digit = number % 3; number = number /3; value = IntDigitToTrinary(digit) + value; } if (negative) { value = "-" + value; } return value; } int TrinaryToInt(string number){ int value{0}; bool negative{false}; size_t pos{0}; if (number[0] == '-') { negative = true; pos = 1; } if (number[0] == '+') { pos = 1; } while(pos < number.size()) { value = value * 3 + TrinaryDigitToInt(number[pos]); pos++; } if (negative) { value *= -1; } return value; } char IntDigitToTrinary(int d){ char value{' '}; if(d >= 0 and d < static_cast(TRINARY_DIGITS.size())) { value = TRINARY_DIGITS[d]; } return value; } int TrinaryDigitToInt(char d){ int value{-1}; size_t pos; pos = TRINARY_DIGITS.find(d); if (pos != string::npos) { value = static_cast(pos); } return value; }