Fix unsigned value representation

This commit is contained in:
Him188 2020-04-02 21:28:31 +08:00
parent 42595a37b0
commit fb635c14bc
2 changed files with 3 additions and 3 deletions

View File

@ -183,8 +183,8 @@ internal operator fun ByteArray.get(range: IntRange): String = buildString {
}
private fun Byte.fixToString(): String {
return when (this.toInt()) {
return when (val b = this.toInt() and 0xff) {
in 0..15 -> "0${this.toString(16).toUpperCase()}"
else -> this.toString(16).toUpperCase()
else -> b.toString(16).toUpperCase()
}
}

View File

@ -9,6 +9,6 @@ internal class ExternalImageTest {
fun testByteArrayGet() {
assertEquals("0F", byteArrayOf(0x0f)[0..0])
assertEquals("10", byteArrayOf(0x10)[0..0])
assertEquals("0FFE", byteArrayOf(0x0F, 0xFE.toByte())[0..0])
assertEquals("0FFE", byteArrayOf(0x0F, 0xFE.toByte())[0..1])
}
}