toBytes method

void toBytes(
  1. int bitOffset,
  2. Uint8List array,
  3. int offset,
  4. int numBytes,
)

@param bitOffset first bit to start writing @param array array to write into. Bytes are written most-significant byte first. This is the opposite of the internal representation, which is exposed by getBitArray @param offset position in array to start writing @param numBytes how many bytes to write

Implementation

void toBytes(int bitOffset, Uint8List array, int offset, int numBytes) {
  for (int i = 0; i < numBytes; i++) {
    int theByte = 0;
    for (int j = 0; j < 8; j++) {
      if (get(bitOffset)) {
        theByte |= 1 << (7 - j);
      }
      bitOffset++;
    }
    array[offset + i] = theByte;
  }
}