Anup Joshi wrote: > Hello Friends, > Just to continue my topic i have found two other techniques from the > internet to find biggest number of given two numbers. i have pasted one > of them below > > int x; // we want to find the minimum of x and y > int y; > int r; // the result goes here > > r = y ^ ((x ^ y)& -(x< y)); // min(x, y) > r = x ^ ((x ^ y)& -(x< y)); // max(x, y) > > i am not really getting how this code works, will spend some time in > understanding it. the other logic with even other topics can be found at > http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax > all credits goes to the author(s) of the above page, i have mailed this just > for your info. ;-) > > Regards > > anup
There is a saying, "Write code like the next person who has to maintain it is a serial killer who knows where you live." That statement applies to this whole thread. There are only three acceptable ways to determine the biggest number of two numbers in C (in order of decreasing clarity): int x = 1, y = 2, z; z = MAX(x, y); z = (x > y ? x : y); if (x > y) z = x; else z = y; Anything else will get you killed by aforementioned serial killer programmer. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
