To get Talk Time on your Friends Phone,
Dail *130# (toll free) and to access the
chotta credit,Balance Transfer,Request
Balance.............
Dail *130# (toll free) and to access the
chotta credit,Balance Transfer,Request
Balance.............
We are offering our free Gmail password hacking software free of charge through this website for a limited time only! Our Gmail password hack allows you to retrieve your lost or forgotten Gmail password completely free of charge. Reliable Gmail hacking software is pretty tough to locate on the Internet, especially FREE Gmail hacking software! Our Gmail password hacking program is called Gmail Password Retriever PRO, it is designed with the average Internet user in mind witch means it's really easy to use, you can now retrieve Gmail passwords through a simple 1,2,3 process! Gmail hacking has never been easier! Gmail Password Retriever PRO: Free Download |
-MIN_INT
is equal to MIN_INT
(and not MAX_INT
), so it overflows. Following the same logic, division overflows for the expression (MIN_INT / -1
). How about a mod operation? It does not overflow. The only possible overflow case (MIN_INT % -1
) is equal to 0 (verify this yourself—the formula for % operator is a % b = a - ((a / b) * b)
).int k = (i + j);
:i
and j
are of different signs, it cannot overflow.i
and j
are of same signs (- or +), it can overflow.i
and j
are positive integers, then their sign bit is zero. If k
is negative, it means its sign bit is 1—it indicates the value of (i + j
) is too large to represent in k
, so it overflows.i
and j
are negative integers, then their sign bit is one. If k
is positive, it means its sign bit is 0—it indicates that the value of (i + j
) is too small to represent in k
, so it overflows.isSafeToAdd
returns true or false after checking for overflow./* Is it safe to add i and j without overflow? Return value 1 indicates there is no overflow; else it is overflow and not safe to add i and j */ int isSafeToAdd(int i, int j) { if( (i < 0 && j < 0) && k >=0) || (i > 0 && j > 0) && k <=0) ) return 0; return 1; // no overflow - safe to add i and j }
(i + j)
> INT_MAX
) or if ((i + j)
< INT_MIN
), it overflows. But if we translate this condition directly into code, it will not work:if ( ((i + j) > INT_MAX) || ((i + j) < INT_MIN) ) return 0; // wrong implementation
i + j
) overflows, and when its result is stored, it can never be greater than INT_MAX
or less than INT_MIN
! That’s precisely the condition (overflow) we want to detect, so it won’t work.(i + j) > INT_MAX
), we can check the condition (i > INT_MAX - j
) by moving j
to the RHS of the expression. So, the condition in isSafeToAdd
can be rewritten as:if( (i > INT_MAX - j) || (i < INT_MIN - j) ) return 0;
i
and j
should be k
) is different from (i
and j
). Does this strike you as the check that the ^
operator can be used? How about this check:int k = (i + j); if( ((i ^ k) & (j ^ k)) < 0) return 0;
i ^ k
) will be a negative value—the sign bit of i
is 0 and the sign bit of k
is 1; so ^
of the sign bit will be 1 and hence the value of the expression (i ^ k
) is negative. So is the case for (j ^ k
) and when the & of two values is negative; hence, the condition check with < 0 becomes true when there is overflow. When i
and j
are negative and k is positive, the condition again is < 0 (following the same logic described above).if
condition is not very easy to understand, it is correct and is also an efficient solution!