• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 441
  • Last Modified:

bigInteger to smaller number in java

hello, am trying to convert a very large  BigInteger into a more workable form in java.  the biginteger is about 20 lines long and i wanted to convert it into maybe a hex-decimal or a base 36 form.  is there any way to do that in java?   thank you in advance
0
gmakungo22
Asked:
gmakungo22
1 Solution
 
enachemcCommented:
use java.math.BigInteger class
0
 
TommySzalapskiCommented:
BigIntegers are stored in binary (or hex, however you want to look at it). It just displays it in decimal for you. If you think of the computer as working in bytes, then it basically stores it in base 256. If you want to store it in a file in this format, you just need to open the file in binary format. However, in the RAM it's already like that so you don't really have to do anything.
0
 
dpearsonCommented:
You want to use the
BigInteger.toString(int radix)
method.

This will convert the BigInteger into a String using whatever base (radix) you would like.  For example, for hex you'd use:
BigInteger myBigInteger;
String hexString = myBigInteger.toString(16);

More here:
http://download.oracle.com/javase/1.4.2/docs/api/java/math/BigInteger.html#toString%28int%29

Doug
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now