[LintCode] Count 1 in Binary

public int countOnes(int num) {
        // write your code here
        int res = 0;
        for(int i = 0 ; i < 32; i++) {
            if((num & (1<<i)) != 0)
                res++;
        }
        return res;
    }