Dart 将两个 Uint8 转换为小端 Uint16

Dart Convert two Uint8 to Uint16 that are little endian

我是 dart 的新手,但我需要使用两个 Uint8(蓝牙响应的一部分)并将它们转换为单个 Uint16。它们也是小端 (LSB),因此第二个值需要移动 8 个字节。我正在努力研究如何在 Dart 中执行此操作。

我已经尝试过类似的方法,但由于值太高,效果并不理想。

var list = new Uint8List(2);
list[0] = 56;
list[1] = 55;
int intValue = list[0] + (list[1] << 8);
Uint16 int16Value = Uint16(intValue);
print(int16Value);

非常感谢。

您可以从列表中获取 ByteData,并且 ByteData 具有各种用于更改字节顺序和获取不同整数类型的函数,更多 here

var data = list.buffer.asByteData();
print(data.getUint16(0, Endian.little));