Right Shift not working properly
bit-shift, c++
Solution
You are missing an assignment operator - the `>>` shift operator does not perform the operation "in-place":
rnd = rnd >> 32;
You could also use the compound shift operator, which applies the shift operation and then assigns the result back to the variable:
rnd >>= 32;
However, in both cases, this code results in undefined behaviour, see Shifting a 32 bit integer by 32 bits:
If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.
So you could get any result from that operation.
Problem
I am right shifting an unsigned int by 32 but it doesn't affect the number at all, why is it happening? ``` int main() { unsigned int rnd=2347483648; cout<<rnd; rnd=rnd>>32; cout<<endl<<rnd; } ``` When the code runs, it displays rnd twice,showing no affect at all. I believe that after right shifting a 32 bit int, shouldn't it display zero?