Hi Everyone, Have a C++ Problem.

Reply

Join Date: Jan 2007
Posts: 1
Reputation: MBeckford05 is an unknown quantity at this point 
Solved Threads: 0
MBeckford05 MBeckford05 is offline Offline
Newbie Poster

Hi Everyone, Have a C++ Problem.

 
0
  #1
Jan 23rd, 2007
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
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,582
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: Hi Everyone, Have a C++ Problem.

 
0
  #2
Jan 23rd, 2007
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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC