How do I perform an unsigned right shift (>>> in Java) in C/C++?

In C, to get an unsigned shift, you just do a shift on an unsigned type.

unsigned int result = (unsigned int)valueToBeShifted >> shiftAmount;

Note that there is no guarantee that >> on a signed type gives you a signed shift in C — this is implementation defined behavior. Most common implementations produce a signed shift if the type is signed, however.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)