How would I convert a number from binary to base 4 without using extra space? For e.g. if binary is 1010 then it would be 22 in base 4? I would like to have the algorithm rather than doing it by some in built functions and what about if I add a condition that I don’t have to generate any string as output. I have to use the given string space to do that.
How would I convert a number from binary to base 4 without using extra
Share
Java’s Integer class has this feature built in (checkout this SO answer). It’s called the radix property of parseInt() and toString(). Note that its important to understand that this is limited to radix vlaues between a MIN and MAX radix value in the Character class so don’t expect to convert numbers to base 1024 without a little effort.
For your question you can do this: