Adding two huge no will cross the integer or what's its range will fall under overflow categories same case goes to negative which fall under underflow .. In both the case numbers will change.. For example no range is -10 to 10 so if x =5 and y=7 then addition will produce the result -9 so u can see we r loosing number this is a overflow same for negative number will produce underflow
Thanks Umesh Sent from my Windows Phone ------------------------------ From: Supraja Jayakumar Sent: Tuesday, June 14, 2011 2:28 AM To: algogeeks@googlegroups.com Subject: Re: [algogeeks] Swapping two variables without using a temporary variable @Wladimir: Can you kindly explain the overflow and underflow you mentioned. Thanks Supraja J On Fri, Jun 10, 2011 at 9:58 PM, Wladimir Tavares <wladimir...@gmail.com>wrote: > Swapping two variables without using a temporary variable using the + and > -: > > x = a; > y = b; > > x = x + y / / x = a + b; > y = x - y / / y = a + b-b = a; > x = x - y / / x = a + b-a = b; > > y = b; > x = a; > > Problems with this approach: > 1) It can cause overflow in the operation (+) > 2) It can cause underflow on operation (-) > > Swapping two variables without using variables > Temporary using XOR: > > x = a; > y = b; > > x = x ^ y; > y = x ^ y / / y = (x xor y) xor y = x xor (y xor y) xor x = 0 = x > x = x ^ y / / x = (x xor y) xor x = (x xor y) xor y xor x = (x xor x) = y > xor y = 0 > > Note that we use some properties of XOR: > > 1) Associativity > 2) Commutativity > 3) X = X 0 XOR > > We have no problems neither underflow nor overflow! > > Wladimir Araujo Tavares > *Federal University of CearĂ¡ > > * > > > > -- > 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 > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- U -- 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 algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.