Help

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2007
Posts: 16
Reputation: kittycat07us is an unknown quantity at this point 
Solved Threads: 0
kittycat07us's Avatar
kittycat07us kittycat07us is offline Offline
Newbie Poster

Help

 
0
  #1
Oct 15th, 2008
Hi, I'm having trouble coming up with a function that scans a word, starting from bit StartingBit, until the first zero bit is found. The function is suppose to return the index of the found bit and if the bit at StartingBit is alrieady what sought, then startingbit is return. And if no bit if found, then UINT_MAX is return.

And here is the main program.

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <bits.h>

using namespace std;

// Print a number in binary:
class Bin
{
public:
Bin(int num)
{ n = num; }
friend ostream& operator<<(ostream& os, const Bin& b)
{
uint bit = 1 << (sizeof(int)*CHAR_BIT - 1);

while (bit)
{
os << ((b.n & bit) ? 1 : 0);
bit >>= 1;
}
return os;
}
private:
int n;
};

unsigned int Scan0(unsigned int word, unsigned int startingBit);

int main()
{
unsigned int i, x;

while (cin >> x)
{
cout << setw(10) << x << " base 10 = " << Bin(x) << " base 2" << endl;
for (i = 0; i < sizeof(unsigned int) * CHAR_BIT; ++i)
cout << "Scan0(x, " << setw(2) << i << ") = "
<< setw(2) << Scan0(x, i) << endl;
cout << endl;
}

return EXIT_SUCCESS;
}

This is the part I need help on.

unsigned int GetBit(unsigned word, int i)
{
return (word>>i) & 01;
}
unsigned int Scan0 (unsigned int word, unsigned int startingBit)
{
int counter;
while (startingBit!=0)
{
if (word>=startingBit)
{
return startingBit;
}
else if (!word)
{
return UINT_MAX;
}
counter++;
}
}
Hello random person reading this.
How are you today?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Help

 
0
  #2
Oct 15th, 2008
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



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