Skip to content

Instantly share code, notes, and snippets.

@tianhaoz95
Created February 27, 2020 04:38
Show Gist options
  • Save tianhaoz95/eaae01e54d6b9eadf535dae0e3c72c6b to your computer and use it in GitHub Desktop.
Save tianhaoz95/eaae01e54d6b9eadf535dae0e3c72c6b to your computer and use it in GitHub Desktop.
Convert a list of bits to a list of bytes
Uint16List bits2bytes(Uint16List bits) {
int byteCnt = bits.length ~/ 8;
Uint16List byteMsg = Uint16List(byteCnt);
for (int i = 0; i < byteCnt; ++i) {
Uint16List bitsOfByte = Uint16List.fromList(bits.getRange(i * 8, i * 8 + 8).toList());
int byte = assembleBits(bitsOfByte);
byteMsg[i] = byte;
}
return byteMsg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment