Well, consider the max unsigned value is MAX. *if MAX-A > B then print "A + B will overflow."*
The trick is scalable to detecting multiplication overflow as well. *if MAX/A > B then print "A x B will overflow."* -Lego On 1/24/07, Ming (Amos) Zhang <[EMAIL PROTECTED]> wrote: > > This is not correct. > > > > Given unsigned char A=255, B=1; > > > > A+B overflows, but ur alg fail to detect it. > > > ------------------------------ > > *From:* algogeeks@googlegroups.com [mailto:[EMAIL PROTECTED] *On > Behalf Of *Santhosh Suresh > *Sent:* Wednesday, January 24, 2007 8:02 AM > *To:* algogeeks@googlegroups.com > *Subject:* [algogeeks] Fwd: [algogeeks] Re: the sum of two unsigned > integers > > > > > say, given the limit of the unsigned as k bits. Find log to base 2^k. If > it's one in both, it'll result in an overflow. > ---------- Forwarded message ---------- > From: *aravind kumar* <[EMAIL PROTECTED]> > Date: Jan 24, 2007 7:10 PM > Subject: [algogeeks] Re: the sum of two unsigned integers > To: algogeeks@googlegroups.com > > check if the sum is less than any of the two numbers that means the sum > resulted in a overflow. > > On 1/24/07, *Abid* <[EMAIL PROTECTED]> wrote: > > > This is an interview question. > What is the simples way to check if the sum of two unsigned integers > has resulted in an overflow. ? > > > > > -- > Regards > Aravind > > "Too often we underestimate the power of a touch, a smile, a kind word, a > listening ear, an honest compliment, or the smallest act of caring, all of > which have the potential to turn a life around." > > "Do I contradict myself? > Very well then I contradict myself, > I am large, I contain multitudes." > - Walt Whitman > > > > > > > -- > Santhosh S > ME05B045 > Dept. of Mechanical Engineering, > IIT Madras, > Chennai-600036 > > > > -- Fear of the LORD is the beginning of knowledge (Proverbs 1:7) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups-beta.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---