suffix

The string that immediately succeeds the hexadecimal representation of a numeric value, empty string by default.

When formatting, this string is placed after the hexadecimal representation. When parsing, the string being parsed must end with this string. The parsing of this suffix is performed in a case-insensitive manner.

Since Kotlin

1.9

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   // By default, `suffix` is an empty string
println(0x3a.toHexString()) // 0000003a
println("0000003a".hexToInt()) // 58

val suffixFormat = HexFormat { number.suffix = "h" }

// `suffix` is placed after the hex representation
println(0x3a.toHexString(suffixFormat)) // 0000003ah
println("0000003ah".hexToByte(suffixFormat)) // 58

// Parsing `suffix` is conducted in a case-insensitive manner
println("0000003aH".hexToInt(suffixFormat)) // 58

// Parsing fails if the input string does not end with the specified suffix.
// "0000003a".hexToInt(suffixFormat) // will fail with IllegalArgumentException 
   //sampleEnd
}