countLeadingZeroBits static method

int countLeadingZeroBits(
  1. String hex
)

Implementation

static int countLeadingZeroBits(String hex) {
  int count = 0;
  for (int i = 0; i < hex.length; i++) {
    int nibble = int.parse(hex[i], radix: 16);
    if (nibble == 0) {
      count += 4;
    } else {
      count += (nibble & 8) == 0 ? 1 : 0;
      count += (nibble & 12) == 0 ? 1 : 0;
      count += (nibble & 14) == 0 ? 1 : 0;
      break;
    }
  }
  return count;
}