![]() |
| ||
| Hi Everyone, Have a C++ Problem. 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 |
| ||
| Re: Hi Everyone, Have a C++ Problem. 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? |
| All times are GMT -4. The time now is 11:36 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC