determines if a value is a multiple of X
#include <iostream>
using namespace std;
int multiple( int );
int main()
{
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;
return 0;
}
int multiple( int num )
{
int mask = 1, mult = 1;
for ( int i = 0; i < 10; i++, mask <<= 1 )
if ( ( num & mask ) != 0 ) {
mult = 0;
break;
}
return mult;
}
Uppercase letters using bitwise AND.
#include <iostream>
using namespace std;
int main()
{
char ch;
for(int i = 0 ; i < 10; i++) {
ch = "a" + i;
cout << ch << " " ;
ch = ch & 223;
cout << ch << "\n";
}
return 0;
}
a A
b B
c C
d D
e E
f F
g G
h H
i I
j J