9 years, 10 months ago.  This question has been closed. Reason: Off Topic

What does c++ expression, uint8_t _value[] = {msb >> 24,msb >> 16, mean?

I have a C++ question.

The following is a part of http://mbed.org/users/yangcq88517/code/SmartLabXBeeAPI/file/e863071f1c9e/Type/DeviceAddress.cpp

SmartLabXbeeAPI

DeviceAddress::DeviceAddress(uint32_t msb,uint32_t lsb, uint16_t net)
{
    uint8_t _value[] = {msb >> 24,msb >> 16,msb >> 8,msb,lsb >> 24,lsb >> 16,lsb >> 8,lsb,net >> 8,net};
    value.assign(_value,_value+10);
}

Could anyone explain the meaning of "msb >> 24" ? What's ">>" doing in this particular case?

1 Answer

9 years, 10 months ago.

Shift it 24 bits to the right. So only the 8 most significant bits are left, and they are placed in the 8-bit variable. The 16 shift leaves only the 16 most significant bits, and since it is placed in an 8-bit variable, effectively only bits 16-23 are left in the result.

Accepted Answer