0

Using C++, Allow a user to input a series of zeros' and one's. stored in an array representing a binary word.

Then display the word horizontally on one line of the screen.

Then the program finds the decimal equilivant on the screen.

I would like some pointers on solving this problem.
I've set the array to hold a binary word. There is a display to enter on zero's and ones up to eight. I am not sure converting binary to decimal, problem converting it to decimal.

Thank you.

MichaelB

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by Infarction
0

Once you have the bit string it's pretty easy. You'll just need to loop from the least significant bit (the one whose value is 1, often the right-most one) through the string to the most significant bit (the one whose value is 2^n, corresponding usually to the left-most). If the bit at the current index is 1, add 2^i, where i is the current index. For finding powers of two, you could also use the left-shift operator (number << shiftAmt), which would pretty much be 1<<i for this case. Make sense?

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.