Kotlin parse Hex String to Long

Mark Gilchrist picture Mark Gilchrist · Jan 14, 2017 · Viewed 13.7k times · Source

I am starting to work in Kotlin and I need to parse a hex String to a long, which in java can be done with

Long.parseLong("ED05265A", 16); 

I can not find anything this in Kotlin, although I can find

val i = "2".toLong()

This is not what I am looking for!

before I write anything from scratch is there a built in function for this?

Answer

voddan picture voddan · Jan 14, 2017

Since Kotlin v1.1 you can use:

"ED05265A".toLong(radix = 16)

Until then use the Java's Long.parseLong.