Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Dart function to convert List<int> to Double?

I'm getting a Bluetooth Characteristic from a Bluetooth controller with flutter blue as a List. This characteristic contains weight measurement of a Bluetooth scale. Is there a function to convert this list of ints to a Double?

I tried to find some background on float representations by reading the IEEE 754 standard. There is the dart library typed_data but I am new to dart and have no experience with this lib.

Example:

I have this List: [191, 100, 29, 173] which is coming from a bluetooth controller as a IEEE754 representation for a float value. Now i believe i have to convert each int to hex and concat these values: bf 64 1d ad

Next thing need to do is convert this to double, but i cannot find a function to convert hex to double. Only int.parse("0xbf641dad").

like image 639
nvano Avatar asked Jul 31 '19 06:07

nvano


1 Answers

I guess your mean to convert the list of ints to a list of floats, not to a single float, right? First, dart has no type called float. Instead it has type double. To convert it, you can use the map() function:

var listInt = [1, 2, 3];
var listDouble = list.map((i) => i.toDouble()).toList();
like image 174
Tidder Avatar answered Oct 04 '22 09:10

Tidder