some texts fixed

This commit is contained in:
sergeych committed 2023-04-01 17:27:52 +01:00
1 parent 641188e92b
commit 6ae2e9f885
5 files changed
+19 -15

No files matched your search

@@ -53,7 +53,7 @@ fun bytesToLong(b: ByteArray): Long {
}
fun bytesToInt(b: ByteArray): Int {
var result: Int = 0
var result = 0
for (i in 0 until 4) {
result = result shl 8
result = result or (b[i].toInt() and 0xFF)
@@ -62,7 +62,7 @@ fun bytesToInt(b: ByteArray): Int {
}
fun bytesToShort(b: ByteArray): Short {
var result: Int = 0
var result = 0
for (i in 0 until 2) {
result = result shl 8
result = result or (b[i].toInt() and 0xFF)
@@ -85,7 +85,7 @@ private val hexDigits = "0123456789ABCDEF"
fun Long.encodeToHex(length: Int = 0): String {
var result = ""
var value = this
var end = if( value >= 0 ) 0L else -1L
val end = if( value >= 0 ) 0L else -1L
// if (value < 0) throw IllegalArgumentException("cant convert to hex negative (ambiguous)")
do {
result = hexDigits[(value and 0x0f).toInt()] + result
@@ -98,12 +98,16 @@ fun Long.encodeToHex(length: Int = 0): String {
fun Int.encodeToHex(length: Int = 0) = (toLong() and 0xFFFFffff).encodeToHex(length)
@Suppress("unused")
fun UInt.encodeToHex(length: Int = 0) = toLong().encodeToHex(length)
@Suppress("unused")
fun Byte.encodeToHex(length: Int = 0) = (toLong() and 0xFF).encodeToHex(length)
@Suppress("unused")
fun UByte.encodeToHex(length: Int = 0) = toLong().encodeToHex(length)
@Suppress("unused")
fun ULong.encodeToHex(length: Int = 0) = toLong().encodeToHex(length)
fun ByteArray.encodeToHex(separator: String = " "): String = joinToString(separator) { it.toUByte().encodeToHex(2) }
@Suppress("unused")
fun Collection<Byte>.encodeToHex(separator: String = " "): String = joinToString(separator) { it.toUByte().encodeToHex(2) }
fun ByteArray.toDump(wide: Boolean = false): String = toDumpLines(wide).joinToString("\n")
@@ -168,6 +172,7 @@ fun ByteArray.toDumpLines(wide: Boolean = false): List<String> {
return lines
}
@Suppress("unused")
fun String.decodeHex(): ByteArray {
val source = this.trim().uppercase()
val result = arrayListOf<Byte>()
@@ -197,4 +202,5 @@ fun ByteArray.flipSelf() {
}
}
@Suppress("unused")
fun ByteArray.flip(): ByteArray = copyOf().also { it.flipSelf() }
@@ -2,10 +2,8 @@
package net.sergeych.bintools
import net.sergeych.bintools.*
/**
* Smart variable-length long encoding tools, async. It gives byte-size gain from 64 bits numbers
* Smart variable-length long encoding tools, async. It gives byte-size gain from 64 bits numbers,
* so it is very useful when encoding big numbers or at least very bui long values. In other cases
* [Varint] works faster, and extra bits it uses does not play
*