reverse method

void reverse()

Reverses all bits in the array.

Implementation

void reverse() {
  final newBits = Uint32List(_bits.length);
  // reverse all int's first
  final len = (_size - 1) ~/ 32;
  final oldBitsLen = len + 1;
  for (int i = 0; i < oldBitsLen; i++) {
    newBits[len - i] = Utils.reverseSign32(_bits[i]);
  }
  // now correct the int's if the bit size isn't a multiple of 32
  if (_size != oldBitsLen * 32) {
    final leftOffset = oldBitsLen * 32 - _size;
    var currentInt = newBits[0] >>> leftOffset;
    for (int i = 1; i < oldBitsLen; i++) {
      final nextInt = newBits[i];
      currentInt |= (nextInt << (32 - leftOffset)).toUnsigned(32);
      newBits[i - 1] = currentInt.toInt();
      currentInt = nextInt >>> leftOffset;
    }
    newBits[oldBitsLen - 1] = currentInt.toInt();
  }
  _bits = newBits;
}