removeLeadingZeros
Defines NumberHexFormat.removeLeadingZeros of the format being built, false
by default.
Refer to NumberHexFormat.removeLeadingZeros for details about how the format option affects the formatting and parsing results.
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
// By default, removeLeadingZeroes is `false`
println(0x3a.toHexString()) // 0000003a
val removeLeadingZerosFormat = HexFormat { number.removeLeadingZeros = true }
// If there are no leading zeros, removeLeadingZeroes has no effect
println(0x3a.toByte().toHexString(removeLeadingZerosFormat)) // 3a
// The leading zeros in the hex representation are removed until minLength is reached.
// By default, minLength is 1.
println(0x3a.toHexString(removeLeadingZerosFormat)) // 3a
println(0.toHexString(removeLeadingZerosFormat)) // 0
// Here minLength is set to 6.
val shorterLengthFormat = HexFormat {
number.removeLeadingZeros = true
number.minLength = 6
}
println(0x3a.toHexString(shorterLengthFormat)) // 00003a
// When minLength is longer than the hex representation, the hex representation is padded with zeros.
// removeLeadingZeros is ignored in this case.
val longerLengthFormat = HexFormat {
number.removeLeadingZeros = true
number.minLength = 12
}
println(0x3a.toHexString(longerLengthFormat)) // 00000000003a
// When parsing, removeLeadingZeros is ignored
println("0000003a".hexToInt(removeLeadingZerosFormat)) // 58
//sampleEnd
}