packBitsIntoBytes static method

Uint8List packBitsIntoBytes(
  1. List<int> bits
)

Pack bits into bytes for thermal printer format

Implementation

static Uint8List packBitsIntoBytes(List<int> bits) {
  List<int> bytes = [];

  for (int i = 0; i < bits.length; i += 8) {
    int byte = 0;
    for (int j = 0; j < 8 && i + j < bits.length; j++) {
      if (bits[i + j] == 1) {
        byte |= (1 << (7 - j));
      }
    }
    bytes.add(byte);
  }

  return Uint8List.fromList(bytes);
}