Unmasking packed data - C++ Operator

C++ examples for Operator:Bit Operator

Description

Unmasking packed data

Demo Code

#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;

    int lowerValue{ (leftShifted & lowerMask) };
    cout << "Lower value unmasked: " << lowerValue << endl;

    int upperValue{ (leftShifted >> maskBits) };
    cout << "Upper value unmasked: " << upperValue << endl;

    return 0;/*from ww w  .ja v  a2  s .c o  m*/
}

Result


Related Tutorials