I am trying to reverse the following bit shift operations to reconstruct
classOfDevice (the code is from https://code.woboq.org/qt5/qtconnectivity/src/bluetooth/qbluetoothdeviceinfo.cpp.html):
const quint32 classOfDevice = 1234; d->minorDeviceClass = static_cast<quint8>((classOfDevice >> 2) & 0x3f); d->majorDeviceClass = static_cast<MajorDeviceClass>((classOfDevice >> 8) & 0x1f); d->serviceClasses = static_cast<ServiceClasses>((classOfDevice >> 13) & 0x7ff);
Now I want something like this:
quint32 classOfDevice = (d->minorDeviceClass << 2) | (d->majorDeviceClass << 8) | (d->serviceClasses << 16);
What is the correct way to achive the reverse conversion?
Source: Windows Questions C++