31 inline void base_convert(
const std::string& source, std::string* sink,
int source_base,
40 bool non_zero_byte =
false;
42 for (
int i = source.size() - 1; i >= 0; --i)
44 int byte = 0xFF & source[i];
45 mpz_add_ui(base10, base10, byte);
47 mpz_mul_ui(base10, base10, source_base);
49 if (byte == 0 && !non_zero_byte)
56 while (mpz_cmp_ui(base10, 0) != 0)
58 unsigned long int remainder = mpz_fdiv_q_ui(base10, base10, sink_base);
59 sink->push_back(0xFF & remainder);
63 for (
int i = 0; i < ms_zeros; ++i) sink->push_back(0);
The global namespace for the Goby project.