Moritz Post
11/12/2021, 11:30 AMByteArray
? a direct conversion via byteArrayOf
does not work since the numbers are unsigned but ubyteArrayOf
does also not work for a reason i don't fully understand. It would be possible to map each number to it - 128
but that seams a bit unefficient. Help would be appreciated.Klitos Kyriacou
11/12/2021, 2:07 PMval list = listOf(0, 1, 80, 127, 128, 255, 256)
val bytes = list.map { it.toByte() }.toByteArray()
println(bytes.contentToString())
Moritz Post
11/12/2021, 2:44 PMPaul Griffith
11/12/2021, 5:12 PMval bytes = ByteArray(list.size) { list[it].toByte() }
is probably more efficient than the above; the ByteArray() pseudo-constructor is treated specially by the compilerKlitos Kyriacou
11/12/2021, 5:20 PM