My main is below, I have gotten this far but do not know how to implement funciton scan0. In my directions it says this, "The function scans

word starting from bit startingBit, toward more significant bits, until the first zero(0) bit is found. The function returns the index of the found bit. If

the bit at startingBit is already what’s sought, then startingBit is returned. If there’s no bit found, then UINTMAX(defined inclimits)is returned. Im not sure how to do this. Any help is appreciated.

unsigned int scan0(unsigned int word, unsigned int startingBit;

extern const int N = sizeof(int) * CHAR_BIT; // # of bits in an int

int main()

{

unsigned int i, x;

while (cin >> x)

{

cout << setw(10) << x << " base 10 = "

<< bitset<N>(x) << " base 2" << endl;

for (i = 0; i < static_cast<unsigned int>(N); ++i)

cout << "scan0(x, " << setw(2) << i << ") = "

<< setw(2) << scan0(x, i) << endl;

cout << endl;

}

return EXIT_SUCCESS;

}')

word starting from bit startingBit, toward more significant bits, until the first zero(0) bit is found. The function returns the index of the found bit. If

the bit at startingBit is already what’s sought, then startingBit is returned. If there’s no bit found, then UINTMAX(defined inclimits)is returned. Im not sure how to do this. Any help is appreciated.

unsigned int scan0(unsigned int word, unsigned int startingBit;

extern const int N = sizeof(int) * CHAR_BIT; // # of bits in an int

int main()

{

unsigned int i, x;

while (cin >> x)

{

cout << setw(10) << x << " base 10 = "

<< bitset<N>(x) << " base 2" << endl;

for (i = 0; i < static_cast<unsigned int>(N); ++i)

cout << "scan0(x, " << setw(2) << i << ") = "

<< setw(2) << scan0(x, i) << endl;

cout << endl;

}

return EXIT_SUCCESS;

}')

Last edited on

Fascinating,

* It seems that the startingBit is an index of a bit.

You surely know

http://www.cplusplus.com/reference/algorithm/find/

The "scan" is essentially a "find".

While the std::find searches through (iterator) range [first, last)

your scan searches (indices) range [startingBit, most-significant-bit]

While std::find searches any value from any container,

your scan searches 0 from*wherever you have your bits*.

The function scans word starting from bit startingBit, toward more significant bits, until the first zero(0) bit is found. * The function returns the index of the found bit. * If the bit at startingBit is already what’s sought, then startingBit is returned. * If there’s no bit found, then UINTMAX(defined inclimits) is returned. |

* It seems that the startingBit is an index of a bit.

You surely know

`std::find`

?http://www.cplusplus.com/reference/algorithm/find/

The "scan" is essentially a "find".

While the std::find searches through (iterator) range [first, last)

your scan searches (indices) range [startingBit, most-significant-bit]

While std::find searches any value from any container,

your scan searches 0 from

Topic archived. No new replies allowed.