Строки (C)
Строки
1 #include <stdio.h>
2 #include <string.h>
3
4 int main() {
5 char* binStr = "101001";
6
7 int multiplier = 1;
8 int dec = 0;
9
10 for (int i = strlen(binStr)-1; i >= 0; i--) {
11 if (binStr[i] == '1') {
12 dec += multiplier;
13 }
14 multiplier *= 2;
15 }
16
17 printf("%s\n%d", binStr, dec);
18 }