Reputation: 314
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
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