Kotlin will mark a hexadecimal string long

I'm starting to work in Kotlin, and I need to parse the hexadecimal string to the end, which in java can be done with

Long.parseLong("ED05265A", 16); 

I can’t find anything in Kotlin, although I can find

val i = "2".toLong()

This is not what I'm looking for!

before writing anything from scratch, is there a built-in function for this?

+8
source share
2 answers

You can just 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 the Java built-in classes and methods.

+7
source

Starting with Kotlin v1.1 you can use:

"ED05265A".toLong(radix = 16)

Use Java before that Long.parseLong.

+16
source

Source: https://habr.com/ru/post/1666784/


All Articles