Converting hex string to byte value

How do I convert
val hexString = "FF"
to Byte value of 255.

Doing
hexString.toInt(16).toByte()
gives -1 as result.

The Byte type is signed and therefore only holds values between -128 and 127.

2 Likes

hexString.toInt(16).toUByte()

It works ! I forgot about UByte type :smiley: Thank you