C++ examples for Operator:Bit Operator
Determines if a value is a multiple of X.
#include <iostream> using namespace std; bool multiple( int ); int main() //from ww w.j a v a2 s. c o m { int y; cout << "Enter an integer between 1 and 32000: "; cin >> y; if ( multiple( y ) ) cout << y << " is a multiple of X" << endl; else cout << y << " is not a multiple of X" << endl; } // determine if num is a multiple of X bool multiple( int num ) { bool mult = true; for ( int i = 0, mask = 1; i < 10; ++i, mask <<= 1 ) if ( ( num & mask ) != 0 ) { mult = false; break; } return mult; } // end function multiple