Is bitmask necessary when assigning a value from a big type to a small one?

Viewed 235

Lets say I want to store the low 16 bits of a uint32_t in a uint16_t on windows, I could do it either

uint32_t value = 123456789;
uint16_t low1 = value; //like this
uint16_t low2 = value & 0xFFFF; //or this

There appears to be no difference in the results but I couldn't find any documentation explicitly stating that this is defined behavior. Could it be different under circumstances X or Y? Or is this just how it works?

2 Answers
Related