size = received[0] val body = received.slice(1 until size + 1) val checkSum = received[size + 1] val sum = body.map { it.toLong() and 0xff }.sum() val isValid = (sum and 0xff) == (checkSum.toLong() and 0xff) println(isValid)
= received[0] val body = received.slice(1 until size + 1) val checkSum = received[size + 1] //val sum = body.map { it.toLong() and 0xff }.sum() val sum = body.sum() //val isValid = (sum and 0xff) == (checkSum.toLong() and 0xff) val isValid = sum and 0xff == checkSum.toInt() println(isValid)