Created
February 27, 2020 04:38
-
-
Save tianhaoz95/eaae01e54d6b9eadf535dae0e3c72c6b to your computer and use it in GitHub Desktop.
Convert a list of bits to a list of bytes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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