Unsolved Converting big number to base 24
-
I want to display array of 20 bytes as a number with base 24. Can Qt do this conversion?
-
yes, it possible in Qt.
int QString::toInt(bool *ok = Q_NULLPTR, int base = 10) const
-
My big number has 160 bits. QString.toInt can't handle it.
-
you can use ::ToULongLong , ::toULong ..
-
Still only 64 bits...
-
@MartinD
Hi,
It's very basic math:BigIntType x; QString number; while (x != 0) { char reminder = x % 24; x /= 24; number += reminder < 10 ? '0' + reminder : 'A' + reminder - 10; } std::reverse(number.begin(), number.end());
Your number system is bad, chose one that's a power of 2, so you can skip the divisions and use bit-wise operations instead.
Kind regards.
-
I used the class in http://stackoverflow.com/questions/4735622/convert-large-hex-string-to-decimal-string . Nice code, easy to implement base 24 conversions.
-
Boost multiprecision is probably the most ready available bignum library you could use for this task. just use
cpp_int
asBigIntType
in @kshegunov 's algorithm