binaryToDecimalString function

int binaryToDecimalString(
  1. String s
)

二进制转十进制

Implementation

int binaryToDecimalString(String s) {
  if (s.isNotEmpty) {
    try {
      int total = 0;
      List<String> list = s.split('');
      int size = list.length;
      for (int i = 0; i < size; i++) {
        total += int.parse(list[i]) * pow(2, size - 1 - i).toInt();
      }
      return total;
    } catch (e) {
      print('binary to decimal is failed');
    }
  }
  return 0;
}