11 if (sourceBaseSet.empty() || targetBaseSet.empty())
12 throw std::invalid_argument(
"Invalid base character set");
52 }
while (!value.empty() &&
66 size_t length = x.length();
67 for (
size_t i = 0; i < length; ++i) {
68 size_t j = i + 1 + x.length() - length;
74 quotient.push_back(baseDigits[value / y]);
75 x =
dec2base(baseDigits, value % y) + x.substr(j);
79 unsigned int remainder =
base2dec(baseDigits, x);
82 size_t n = quotient.find_first_not_of(baseDigits[0]);
83 if (n != std::string::npos) {
84 x = quotient.substr(n);
95 unsigned int numberBase = (
unsigned int)baseDigits.length();
98 result.push_back(baseDigits[value % numberBase]);
110 unsigned int numberBase = (
unsigned int)baseDigits.length();
112 for (
size_t i = 0; i < value.length(); ++i) {
113 result *= numberBase;
114 size_t c = baseDigits.find(value[i]);
115 if (c == std::string::npos)
116 throw std::runtime_error(
"base_converter::Invalid character");
118 result += (
unsigned int)c;
bool dec2hex(std::string const &input, std::string const &wanted)
static constexpr char const * binary_set()
static unsigned int base2dec(std::string const &baseDigits, std::string const &value)
static std::string dec_to_hex(std::string value)
base_converter(std::string const &sourceBaseSet, std::string const &targetBaseSet)
std::string convert(std::string value) const
static constexpr char const * decimal_set()
static std::string dec2base(std::string const &baseDigits, unsigned int value)
static unsigned int divide(std::string const &baseDigits, std::string &x, unsigned int y)
static std::string dec_to_bin(std::string value)
bool dec2bin(std::string const &input, std::string const &wanted)
static constexpr char const * hex_set()
bool hex2dec(std::string const &input, std::string const &wanted)
std::string source_base_set_
static std::string hex_to_dec(std::string value)
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
unsigned int get_target_base() const
std::string target_base_set_
bool bin2dec(std::string const &input, std::string const &wanted)
static std::string bin_to_dec(std::string value)