• + 0 comments

    For x > 0, you can just subtract input from an equal number of "on" bits, e.g.

    if x = 1010 perform: 1111 - 1010 and that's the answer.

    I haven't found a really easy way (in C++) of making that 1111 number, though.