Logical right shift (source code)

= Logical right shift
{title2=$\operatorname{LSR}_k(a)=\lfloor a/2^k\rfloor$}

A <logical right shift> moves <bits> toward less significant positions, discards those shifted out, and fills the high positions with zero. On the <unsigned interpretation> of a <machine word>, it computes the quotient in <integer division> by $2^k$. Indeed, splitting the <binary representation> after its lowest $k$ <bits> gives $a=2^kq+r$ with $0\leq r<2^k$; the retained upper <bits> represent $q$. A fixed-width <left bit shift> by $n-k$ followed by a <logical right shift> by $n-k$ extracts precisely the low $k$ <bits>, giving the remainder.