how (s+e)>>1 works as we always write (s+e)/2 to find mid point in binary search
and please could u again explain me that floating part
(s+e)>>1 and floating part
hello @TheSourabh “>>” is a binary operator called as right shift operator
(right shift) Takes two numbers, right shifts the bits of the first operand, the second operand decides the number of places to shift.Similarly right shifting (x>>y) is equivalent to dividing x with 2^y.
for eg if we have 9 which has binary representation as 1001 if we do 9>>1 that means shift one bit rightward thus we get 0100 as output which formulates to 4 which is also (9/2). similarly doing 9>>2 will result in 0010 that is 2 which is also (9/2^2).
so doing (s+e)>>1 will result same value as (s+e)/2.
why we did this ?
because binary operations(&,|,>>,<<,~) are faster than airthmetic operations (+,/,*,-)
If you feel you have doubt you can ask here i will answer.
Happy Learning !!