Anurag Shukla
Anurag Shukla

Reputation: 314

Kotlin: How to convert from binary to decimal

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

Upvotes: 7

Views: 5102

Answers (1)

erolkaya84
erolkaya84

Reputation: 1849

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"

Upvotes: 22

Related Questions