I know that '<<' is a SHL and '>>' is a SHR. |
You know that an acronym SHL exists, but you don't know what it means?
bitshift
We have a 8-bit number: 00001011 (dec 11)
We shift bits 2 positions to left and get: 00101100 (dec 44)
In other words: 11<<2 == 44
When a bit shift one position to left, its value doubles. Therefore, n<<3 is same as n*2*2*2.
Shifting right halves value, so n>>2 equals n/4.
1<<(S-1) is thus same as 1*2^(S-1)
Math would say that:
(gai + add)>>S
== gai>>S + add>>S
== gai/(2^S) + add/(2^S)
== gai/(2^S) + 1*(2^(S-1))/(2^S)
== gai/(2^S) + 1/2
However, integers don't have fractions, and shifting a bit out from either side will throw it away. Integer division does discard remainder, i.e. it does round down.
It does look like these equations attempt to round more intuitively, i.e. that 1/2->1, 3/4->1, 1/4->0, etc