subnetToPrefix method

int? subnetToPrefix(
  1. String? subnet
)

Implementation

int? subnetToPrefix(String? subnet) {
  if (subnet == null || subnet == "") {
    return null;
  }
  List<String> chunks = subnet.split(".");
  List<String> binary =
      chunks.map((String s) => int.parse(s).toRadixString(2)).toList();
  String ones = binary.join().replaceAll("0", "");
  return ones.length;
}