News for hackers. Stuff that matters.
Re:Calculate n + 1 without using + or - or * or / by veyron on Monday July 04, 2011 @06:48PM (#2728107)
Basically replicate the carry process in the form of bit ops:

    def inc(n):
        x = 1
        while n & 1 == 1:
            n = n >> 1
            x = x << 1
        n = n | 1
        while not x == 1:
            x = x >> 1
            n = n << 1
        return n

There are no comments on this comment yet.