L
lovecreatesbea...
The following function determines the maximum of two integers. It
works on my machine.
If (a[0] - a[1]) is negative, what's the first bit of: (unsigned)(a[0]
- a[1])? Is it 0 or 1?
#include <limits.h>
int max(int n1, int n2)
{
int a[2];
a[0] = n1, a[1] = n2;
return a[((unsigned)(a[0] - a[1]) >> sizeof n1 * CHAR_BIT - 1)];
}
Thank you for your time
works on my machine.
If (a[0] - a[1]) is negative, what's the first bit of: (unsigned)(a[0]
- a[1])? Is it 0 or 1?
#include <limits.h>
int max(int n1, int n2)
{
int a[2];
a[0] = n1, a[1] = n2;
return a[((unsigned)(a[0] - a[1]) >> sizeof n1 * CHAR_BIT - 1)];
}
Thank you for your time