Skip to content

Instantly share code, notes, and snippets.

@GeordieP
Created December 5, 2013 20:14
Show Gist options
  • Save GeordieP/7813060 to your computer and use it in GitHub Desktop.
Save GeordieP/7813060 to your computer and use it in GitHub Desktop.
Part 1 of binary conversion assignment
#include <stdio.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
cout << "Enter binary: ";
string binary;
getline(cin,binary);
int total = 0;
for (int i = 0; i < binary.length(); i++){
total += (binary[i] - '0') * pow(2, ((binary.length() - 1) - i));
}
cout << "Decimal: " << total << "\n";
getchar();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment