Home > Enterprise >  convert biginteger to bit
convert biginteger to bit

Time:07-23

I am stuck with an exercise at JetBrain Academy, with BigInteger(Kotlin). I should write a code snippet to convert a (BigInteger) number of exbibyte into bits: if the input is 1 as BigInteger, it displays 9223372036854775808. In the hints it says I should use pow(63).(Exbibyte = 2^63 = 9 223 372 036 854 775 808‬ Bit) My problem is if I use pow(), I can use only double as the biggest range. But with double I cannot display a BigInteger number.

CodePudding user response:

In your case, I hope it should work:

val exbibytes = BigInteger.valueOf(1)
val oneExbibyteInBits = BigInteger.valueOf(2).pow(63)

val exbibytesInBits = exbibytes.multiply(oneExbibyteInBits)
  • Related