Kotlin: How to convert from binary to decimal

Viewed 2045

I need to convert from Binary String to Int or Long in Kotlin. Is there any inbuilt utility method available for the same?

1 Answers

that's how you can do;

println("11001".toInt(2))
println("11001".toLong(2))

As Joffrey said in the comment, "the 2 here is the number's base. That's why it's 2 for binary, would be 16 for hexadecimal"

Related