!fix Long.encodeToHex bug, rewritten with new types

+fast BitSet set with enums support
This commit is contained in:
sergeych committed 2024-12-23 01:07:04 +03:00
1 parent f6d2422cc1
commit 3f83e842fe
5 files changed
+458 -16

No files matched your search

@@ -84,13 +84,11 @@ private val hexDigits = "0123456789ABCDEF"
fun Long.encodeToHex(length: Int = 0): String {
var result = ""
var value = this
val end = if( value >= 0 ) 0L else -1L
// if (value < 0) throw IllegalArgumentException("cant convert to hex negative (ambiguous)")
var value = this.toULong()
do {
result = hexDigits[(value and 0x0f).toInt()] + result
result = hexDigits[(value and 0x0fu).toInt()] + result
value = value shr 4
} while (value != end)
} while (value != 0UL)
while (result.length < length) result = "0" + result
return result
}