Question

I want to convert a base16 string to base32 String. For example, if i have a base-16 String -- "000000000288" now i want to convert it to it base-32 counterpart ("K-8").

There is a website which does it:

http://www.unitconversion.org/unit_converter/numbers.html

Was it helpful?

Solution

I think that you can do it this way:

int number = Integer.parseInt("000000000288", 16);
String base32 = Integer.toString(number, 32);

Edit: Sorry, I forgot to add the radix parameter to the first line. I have changed it now.

OTHER TIPS

I find java's BigInteger to be the best among them all for bit manipulation. Among its wide usages (mainly with storing huge numbers, upto your memory stack can allow and for its wide array of supported operations), you do have the option for base conversion from 2 to 36.

Example Code :

BigInteger num=new BigInteger("000000000288",16);     //Store as Hexa

//Display the result using BigInteger.toString(radix)
System.out.println("Result = "+num.toString(32));    //Showing result in 32 base

Ofcourse if you are dealing with numbers having Fractional part, you will have to use Magicode's method of Integer.toString(radix). Or if your number is bigger than what int can store, I suggest you run your own function for Base Conversion for the fraction part.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top