All pastes #507907 Raw Edit

Mine

public text v1 · immutable
·published 2007-05-24 20:01 UTC
rendered paste body
    public static int countBits(int i) {
        int bits = 0;
        int temp = i;
        while (temp > 0) {
            temp = temp / 2;
            bits++;
        }
        return bits;
    }
    
    public static int invertBits(int i) {
        return i ^ ((int)Math.pow(2, countBits(i)) - 1);
    }