C++ bitwise Operator & Converts characters to uppercase
#include <iostream> using namespace std; int main()/*from ww w . j a va2 s.c o m*/ { char first, middle, last; // Will hold user's initials int bitmask=223; // 11011111 in binary cout << "What is your first initial? "; cin >> first; cout << "What is your middle initial? "; cin >> middle; cout << "What is your last initial? "; cin >> last; // Ensure that initials are in uppercase. first = first & bitmask; // Turn off bit 5 if middle = middle & bitmask; // it is not already last = last & bitmask; // turned off. cout << "Your initials are " << first << " " << middle << " " << last; return 0; }