Created
January 30, 2012 09:32
-
-
Save dioncodes/1703557 to your computer and use it in GitHub Desktop.
binary to decimal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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