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