Skip to content

Instantly share code, notes, and snippets.

@dioncodes
Created January 30, 2012 09:32
Show Gist options
  • Save dioncodes/1703557 to your computer and use it in GitHub Desktop.
Save dioncodes/1703557 to your computer and use it in GitHub Desktop.
binary to decimal
int binarytodecimal() {
string eingabe;
int ergebnis;
cout << "Enter a binary number (0-1): ";
cin >> eingabe;
int zahl;
string zahlk, zahls;
for(int i=eingabe.length(), multi=1;i>=0;i--,multi*=2) {
zahlk = eingabe[i];
zahl = atoi(zahlk.c_str());
zahl = zahl * multi;
ergebnis = ergebnis + zahl;
//cout << zahl;
}
cout << endl << endl << "The binary " << eingabe << " is in decimal: " << ergebnis << endl << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment