Kotlin parse Hex String to Long

♀尐吖头ヾ 提交于 2020-01-02 01:29:27

问题


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?


回答1:


You can simply use

java.lang.Long.parseLong("ED05265A", 16)

Or

import java.lang.Long.parseLong 

[...] 

parseLong("ED05265A", 16)

Kotlin is compatible with Java, and you can, and should, use Java's built-in classes and methods.




回答2:


Since Kotlin v1.1 you can use:

"ED05265A".toLong(radix = 16)

Until then use the Java's Long.parseLong.



来源:https://stackoverflow.com/questions/41651704/kotlin-parse-hex-string-to-long

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!