B
bg_ie
Hi,
I have a function which compares two unsigned ints and returns their
difference in order to establish which is the greater of the two.
int Compare(unsigned int time_left, unsigned int time_right)
{
return (time_left - time_right);
}
usage -
if( Compare(time_left, time_right) > 0)
// the time has come.
The problem is that when time_left is 5 and time_right is 10, I get -5,
but if time_left is 5 and time_right is 0xc0000005 (a number greater
than 5) I get a positive value when I wish to get a negitive one.
I understand why I get this positive value - because the negaitve bit
is set in time_right, but how can I change my code so that I get the
desired results.
Thanks for your help,
Barry.
I have a function which compares two unsigned ints and returns their
difference in order to establish which is the greater of the two.
int Compare(unsigned int time_left, unsigned int time_right)
{
return (time_left - time_right);
}
usage -
if( Compare(time_left, time_right) > 0)
// the time has come.
The problem is that when time_left is 5 and time_right is 10, I get -5,
but if time_left is 5 and time_right is 0xc0000005 (a number greater
than 5) I get a positive value when I wish to get a negitive one.
I understand why I get this positive value - because the negaitve bit
is set in time_right, but how can I change my code so that I get the
desired results.
Thanks for your help,
Barry.