0

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

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by minigweek
1

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).

Votes + Comments
Correct!
0

^^ 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!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.