Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int toDecimal(string binary) {
- int decimal = 0;
- for(int i=0; i<binary.size(); i++) {
- decimal *= 2;
- decimal += binary[i] - '0';
- }
- return decimal;
- }
- int main() {
- cout << toDecimal("1011");
- return 0;
- }
Add Comment
Please, Sign In to add comment