C++ examples for Operator:Bit Operator
Using a mask to pack values into a variable
#include <iostream> using namespace std; int main(int argc, char* argv[]) { const int maskBits{ 16 }; int leftShifted{ 0x00001010 << maskBits }; cout << showbase << hex; cout << "Left shifted: " << leftShifted << endl; int lowerMask{ 0x0000FFFF }; leftShifted |= (0x11110110 & lowerMask); cout << "Packed left shifted: " << leftShifted << endl; return 0;/*from w ww. ja v a2s. c o m*/ }