asByteList function

List<int> asByteList(
  1. List<int> bits
)

Implementation

List<int> asByteList(List<int> bits) {
  final bytes = <int>[];

  for (int i = 0; i < bits.length; i += 8) {
    int byte = 0;
    for (int j = 0; j < 8; j++) {
      if (i + j >= bits.length) continue; // avoid out of bounds
      byte |= (bits[i + j] << (7 - j));
    }
    bytes.add(byte);
  }
  return bytes;
}