C语言/C++——二进制、十进制互换 #include<iostream> using namespace std; int twototen(int num) { int w = 1, h, sum = 0; while (num) { h = num % 10; num /= 10; sum += h * w; w *= 2; } return sum; }