some support for fixed number

This commit is contained in:
sergeych committed 2023-04-01 16:12:20 +01:00
1 parent 5b8df2ff20
commit 86eb5e9d7f
8 files changed
+81 -15

No files matched your search

@@ -20,6 +20,15 @@ fun intToBytes(value: Int): ByteArray {
}
return result
}
fun shortToBytes(value: Short): ByteArray {
var l = value.toInt()
val result = ByteArray(2)
for (i in 1 downTo 0) {
result[i] = (l and 0xFF).toByte()
l = l shr 8
}
return result
}
fun uintToBytes(value: UInt): ByteArray {
var l = value
@@ -52,6 +61,15 @@ fun bytesToInt(b: ByteArray): Int {
return result
}
fun bytesToShort(b: ByteArray): Short {
var result: Int = 0
for (i in 0 until 2) {
result = result shl 8
result = result or (b[i].toInt() and 0xFF)
}
return result.toShort()
}
fun bytesToUInt(b: ByteArray): UInt {
var result = 0u
for (i in 0 until 4) {