Can you do us all a favor? Plz don't uz AOLspk in hr. U dont need 2 uz cute wurdz here.
If you're asking for help in a forum, the absolute best thing you can do is be as clear as possible, which means stop speaking like you're in some lol d00d chat room. Doing anything else will detract from your potential to recieve help.
alc6379
Cookie... That's it
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
just a quick 'n' dirty hack here :P
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int Bin2dec(string strBin)
{
int nSum = 0, k = strBin.length() - 1;
for (int i = 0; i < strBin.length(); i++)
nSum += (strBin[i] - '0') * pow(2, k--);
return nSum;
}
int main(void)
{
string strBin;
cout << "Enter binary number :";
cin >> strBin;
cout << "Decimal value: " << Bin2dec(strBin) << endl;
return 0;
}
r0ckbaer
Junior Poster in Training
55 posts since Dec 2003
Reputation Points: 13
Solved Threads: 6
That's not important, he wanted to have his thinggy corrected, and that's what i did...this answer was specifically addressed to his problem
r0ckbaer
Junior Poster in Training
55 posts since Dec 2003
Reputation Points: 13
Solved Threads: 6
ANd! To aDd to WhAT aLEx saId; pEAsE uSE prOPeR . punCtuATIon, ANd caPITaliSatION: IN yOuR quEstIonS?
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
yes, that cost me about 5 minutes to deliberately get wrong ;)
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
not having a go, dont worry! just saying that if there is anything that cant be sorted then a few people have discussed the topic of going both ways (b2d, d2b) on a different thread. btw where is the pow function defined ? is it in ? would certainly simplify my own code version... :)
Yes, pow() is in cmath, but likes to see doubles for arguments, or at least pow(2.0, k--)
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417