i am writing a binary to decmal conversion program in c++ and am so lost just wondering if anyone out there could lend a hand to a lost soul

also am curious as to how decimal to hexidecimal would work too just wanting to learn more about programming language and am very in experewienced

Recommended Answers

All 2 Replies

I have tried to do this before. Just read a tutorial on how to do it by hand and make a function or whatever.

Check this out: http://www.permadi.com/tutorial/numBinToDec/index.html

Pretty much, you move left starting from the first binary digit on the right. You increment the power from 0, and multiply the digit by 2^power. So:

1010

0*(2^0) = 0
1*(2^1) = 2
0*(2^2) = 0
1*(2^3) = 8

0 + 2 + 0 + 8 = 10

1010 = 10

I'm pretty sure that you can do this conversion for any number base system. Like for base 3: instead of Digit*(2^Power), you would do Digit*(3^Power).

commented: Correct! +2

^^ correct he is , just try to convert the above algorithm into a c++ code and see. Post your code if it fails, and we will further look into it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.