upperCase

Specifies whether upper-case hexadecimal digits should be used for formatting, false by default.

When this option is set to true, formatting functions will use upper-case hexadecimal digits (0-9, A-F) to create the hexadecimal representation of the values being formatted. Otherwise, lower-case hexadecimal digits (0-9, a-f) will be used.

This option affects the formatting results for both byte arrays and numeric values. However, it has no effect on parsing, which is always performed in a case-insensitive manner.

Note: This option affects only the case of hexadecimal digits and does not influence other elements like BytesHexFormat.bytePrefix or NumberHexFormat.suffix.

Since Kotlin

1.9

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   // By default, upperCase is set to false, so lower-case hexadecimal digits are used when formatting.
println(58.toHexString()) // 0000003a
println(58.toHexString(HexFormat.Default)) // 0000003a

// Setting upperCase to true changes the hexadecimal digits to upper-case.
println(58.toHexString(HexFormat { upperCase = true })) // 0000003A
println(58.toHexString(HexFormat.UpperCase)) // 0000003A

// The upperCase option affects only the case of hexadecimal digits.
val format = HexFormat {
    upperCase = true
    number.prefix = "0x"
}
println(58.toHexString(format)) // 0x0000003A

// The upperCase option also affects how byte arrays are formatted.
println(byteArrayOf(0x1b, 0xe6.toByte()).toHexString(format)) // 1BE6

// The upperCase option does not affect parsing; parsing is always case-insensitive.
println("0x0000003a".hexToInt(format)) // 58
println("\"1BE6\".hexToByteArray(format).contentEquals(byteArrayOf(0x1b, 0xe6.toByte())) is ${"1BE6".hexToByteArray(format).contentEquals(byteArrayOf(0x1b, 0xe6.toByte()))}") // true 
   //sampleEnd
}