or even require using UByte directly instead of Byte (Kotlin Playground):private fun magicallyExtractRightValue(b: UByte): Int { return b.toInt()}对于Kotlin 1.3之前的版本,我建议创建一个扩展功能使用 and :For releases prior to Kotlin 1.3, I recommend creating an extension function to do this using and:fun Byte.toPositiveInt() = toInt() and 0xFF示例用法:val a: List<Int> = listOf(0, 1, 63, 127, 128, 244, 255)println("from ints: $a")val b: List<Byte> = a.map(Int::toByte)println("to bytes: $b")val c: List<Int> = b.map(Byte::toPositiveInt)println("to positive ints: $c")示例输出:from ints: [0, 1, 63, 127, 128, 244, 255]to bytes: [0, 1, 63, 127, -128, -12, -1]to positive ints: [0, 1, 63, 127, 128, 244, 255] 这篇关于如何正确处理Kotlin中大于127的字节值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-15 14:16