0

I need help to read data from an external device. In the specifications is written that every single fetched value is a 24bit signed integer, but I can't correctly read data from Dart (while I can on Java).

Starting from Java (just because it works), I fetch the data as a byte array, then reading a byte give me the correct value:

 byte[] data  = call.argument("mydata");
 Log.d("CONVERT_DATA_datai", String.valueOf(data[4]));

In this case, the output is -1 and it's correct.

In Dart i've seen that there isn't a byte array type but I should use a List<int> instead, so my code is:

 List<int> data = value as List<int>;
 print(data[4].toString());

In this case I get the value 255 which is incorrect, I think because I've to convert it to signed 24bit integer.

Other samples are:

-6 in java, 250 in dart (incorrect)

3 in java, 3 in dart (correct)

How can i solve this problem?

Thanks in advance.

SciFi
  • 119
  • 7
  • The [`int.toSigned`](https://api.dart.dev/stable/dart-core/int/toSigned.html) method might be useful to you. – jamesdlin Nov 09 '22 at 16:00

1 Answers1

1

There is Int8List type in dart:typed_data.

And by accessing Int8List::buffer you can read any number you want.

LacticWhale
  • 209
  • 1
  • 11