@Ayswarya: In twos-complement arithmetic, -x = ~x + 1, so a + ~b + 1 = a +(~b +1) = a + (-b) = a - b.
Dave On Aug 10, 9:23 am, Ayswarya Srinivasan <[email protected]> wrote: > can someone explain how this works- > * > * > *void* *main*(){ > *int* a,b,d; > scanf("%d%d",&a,&b); > d=a+~b+1; > printf("%d",d); > getch(); > > } > > say if a=5 b=6 then > output is -1 > > if ~ is one's complement operator > then > a=0101 > ~b=1001 > > d= 0101+1001+1. which is not -1 > > can someone explain how it works. > > -- > > Regards, > Ayswarya S -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
