What does the following program do?

```
#include
using namespace std;

bool mystery( unsigned );

int main()
{
unsigned x;

cout << "Enter an integer: ";
cin >> x;
cout << boolalpha
<< "The result is " << mystery( x ) << endl;
} // end main

// What does this function do?
bool mystery( unsigned bits )
{
const int SHIFT = 8 * sizeof( unsigned ) - 1;
const unsigned MASK = 1 << SHIFT;
unsigned total = 0;

for ( int i = 0; i < SHIFT + 1; i++, bits <<= 1 )
if ( ( bits & MASK ) == MASK )
++total;

return !( total % 2 );
} // end function mystery
```


The program prints false if the total number of 1s in the bit representation is odd,
and prints true if the number of 1s is even.

Computer Science & Information Technology

You might also like to view...

Starting from your home directory, find all the files that their names start with letter A, B, C, or D.

What will be an ideal response?

Computer Science & Information Technology

Indicate the error in this statement: float total_cost 0.00

A. Variables can not be initialized in the declaration statement. B. It is only missing a ;. C. It is missing a ; and and = between total_cost and 0.00. D. Float should be capitalized.

Computer Science & Information Technology

The Slide Sorter view displays your slides on the top portion of the page, with any speaker notes appearing on the bottom of the page.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

What are common keyboard events? What is the delegate used to create a keyboard event handler, and what is the type of the second parameter to the event handler?

What will be an ideal response?

Computer Science & Information Technology