8 lines
340 B
Kotlin
8 lines
340 B
Kotlin
package io.gitlab.jfronny.hc05ac.util
|
|
|
|
private val Byte.u get() = toUByte()
|
|
private val UByte.s get() = toByte()
|
|
|
|
fun pack(left: Byte, right: Byte): Byte = ((left.u and 0xF0u) or ((right.u and 0xF0u).div(16u)).toUByte()).s
|
|
fun Byte.unpackLeft(): Byte = (this.u and 0xF0u).s
|
|
fun Byte.unpackRight(): Byte = ((this.u and 0x0Fu) * 16u).toByte() |