-1

what data type is suitable for a given 20 digit numbers like 12111111111111111111 and could be converted to binary?

I tried long but it's goes out of range.

Mureinik
  • 297,002
  • 52
  • 306
  • 350

3 Answers3

3

java.math.BigInteger is for "Immutable arbitrary-precision integers" - should fit your needs perfectly.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
1

Try this:

BigInteger b1 = new BigInteger("12111111111111111111");
BigInteger b2 = new BigInteger("12111111111111111112");
System.out.println(b1.add(b2));
System.out.println(" binary format of b1 is : " + b1.toString(2));
SMA
  • 36,381
  • 8
  • 49
  • 73
0

Well u can use bigInteger that is having large length of the number that what u want.

try this.

java.math.BigInteger bignumber = new BigInteger("1211111111111255511236");

hope that will help.

Kishan Bheemajiyani
  • 3,429
  • 5
  • 34
  • 68