Max of two integers without using any conditional operators.
-b)
Solution 1:
===========
max = (a + b + absolute(a - b))/2
If a > b then max = (a + b + a - b)/2 = 2*a/2 = a
otherwise a < b then max = (a + b + b - a)/2 = 2*b/2 = b
Solution 2:
===========
max = b*(((a-b)& 0x8000)>>32) + a*(((b-a)& 0x8000)>>32)
This comment has been removed by the author.
ReplyDeleteI am sorry to say i dont understand your language... So if you can post your comments in english it would be great...
ReplyDeletemax = b*(((a-b)& 0x80)>>7) + a*(((b-a)& 0x80)>>7)
ReplyDeletethis works for me
superb.. algo infact.. by the author