本文介绍了如何从Dart中的Uint8List读取16位int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Uint8List中存储了一个二进制数据,我想从该列表中读取一个16位的int.有什么方便的方法可以帮助您解决此问题吗?
I have a binary data stored in Uint8List and I'd like to read a 16-bit int from that list. Are there any convenience methods to help with this?
(从与同事的交谈中解释)
(paraphrasing from a conversation I had with a colleague)
推荐答案
您可以使用ByteData类:
You can use the ByteData class:
var buffer = new Uint8List(8).buffer;
var bytes = new ByteData.view(buffer);
bytes.getUint16(offset);
(由同事提供的答案解释)
(paraphrased from an answer provided by a colleague)
这篇关于如何从Dart中的Uint8List读取16位int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!