https://kotlinlang.org logo
Title
c

Christian Sousa

07/29/2020, 9:31 AM
Anyone can enlighten me why something like this on typescript works:
let binaryString = "001110110001010001110100110111100100"
console.log(parseInt(binaryString, 2))
// output: 15859142116
But not on Kotlin:
var binaryNumber:String = "001110110001010001110100110111100100"
    
    try {
    var retr = binaryNumber.toInt(2)
    println(retr)        
    } catch(error: Throwable){
        println(error)
    }
// java.lang.NumberFormatException: Invalid number format: '001110110001010001110100110111100100'
d

diesieben07

07/29/2020, 9:49 AM
Int
is 32 bit, your number is larger than 32 bit.
toLong
works fine
4
c

Christian Sousa

07/29/2020, 3:03 PM
Thanks!