Here is code in Java:
int a = 456;
int b = 5;
String s = Integer.toString(a, b);
System.out.println(s);
Now I want the same in C++, but all the conversions i find convert to base 10 only. I ofc dont want to implement this by mysleft, why to write something what already exists
although std::strtol
is more flexible, in a controlled case you can use itoa
as well.
int a = 456;
int b = 5;
char buffer[32];
itoa(a, buffer, b);
If you want base 8 or 16 you can easily use the string manipulators std::oct
and std::hex
. If you want arbitrary bases, I suggest checking out this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With