BitArray.parseBinary constructor

BitArray.parseBinary(
  1. String bitString
)

Create a bit array from a binary string.

Implementation

factory BitArray.parseBinary(String bitString) {
  final data = Uint32List((bitString.length + 31) >> 5);
  for (var i = 0; i < bitString.length; i++) {
    if (bitString[i] == '1') {
      data[i >> 5] |= _bitMask(i);
    } else if (bitString[i] != '0') {
      throw FormatException('Binary string should consist of 0s and 1s only');
    }
  }
  return BitArray._(bitString.length, data);
}