This is not a homework problem, I am too old to get home works :)
So, ideally I am trying to convert a number in a given base to another given base.
Can someone please share the logic, then probably I can write the code myself. Not able to find anything online surprisingly.
The answer depends on whether or not you can use a primitive, such as an
long for your representation.
If you can, the algorithm is reasonably simple: convert the number in base X to a primitive representation, then convert that representation to base Y.
To convert a number to primitive, use this algorithm:
res, and set it to zero
To convert back, use this algorithm:
digit = num % Y
num /= Y
numis not zero
If your number is too big for a primitive, such as
long, you need to build a class for holding numbers greater than primitives. I would recommend using
BigInteger initially, and then replacing it with your own implementation.