When I attempt to retrieve a value from the device via Bluetooth, it comes out in ASCII, as a null terminated big-endian value. The device software is written in C. I want to retrieve the decimal value, i.e. 0 instead of 48, 1 instead of 49, 9 instead of 57, etc.
@Throws(IOException::class)
fun receiveData(socket: BluetoothSocket ? ): Int {
val buffer = ByteArray(4)
val input = ByteArrayInputStream(buffer)
val inputStream = socket!!.inputStream
inputStream.read(buffer)
println("Value: " + input.read().toString()) // Value is 48 instead of 0, for example.
return input.read()
}
How can I retrieve the value I want?