+ 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?
5 Réponses
+ 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!
+ 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.
+ 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 :)
+ 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.