Here is the function that finds the greater of two numbers:
int larger(int a,int b)
{
int c=a-b;
int k=c>>31&1;
int max=a-k*c;
return max;
}
To find the greatest of three numbers, call it such as:
larger(a,larger(b,c));
How does this work?
cwill be negative ifa < belse it will positive. Now a negative number will have its most significant bit(MSB) set.This step assumes that
sizeof(int)is4bytes and extracts the MSB ofcink. Sokis either0or1replacing
c = a-bin this we getmax = a-k*(a-b). So when