+ 1

Decimal to any base converter

Hello, I was reading about the stoi and strtol functions and I was wondering wether there is in C++ any function (from some certain library) that does the opposite, which means that converts from decimal to any base?

28th Sep 2019, 5:18 PM
Ledio Deda
Ledio Deda - avatar
4 ответов
+ 5
Oh yes I heard about *sprintf* but I was looking for a general one. I will see more about 'itoa' (btw its not a typo, so its not iota what u were talking about right?). Thanks a lot!
28th Sep 2019, 6:46 PM
Ledio Deda
Ledio Deda - avatar
+ 2
There is `sprintf` but it can only do decimal/hex/octal. I'm not aware of some builtin way to convert to arbitrary bases. `itoa` can do it but it is non-standard.
28th Sep 2019, 6:40 PM
Schindlabua
Schindlabua - avatar
+ 2
Ha, no, itoa as in "integer to string". Theres a whole class of these like atoi, ltoa, lltoa etc. All of them nonstandard though :)
28th Sep 2019, 7:06 PM
Schindlabua
Schindlabua - avatar
+ 2
Martin Taylor Thanks for ths information. It's not for every base, but for 2, 8 and 16 it really works even with negative numbers.
2nd Oct 2019, 7:46 AM
Ledio Deda
Ledio Deda - avatar