Getting RTE when I'm calculating complement of a positive integer

I’m calculating the complement of a positive integer.

Here is my code:

int findComplement(int num) {
    int bits = floor(log2(num))+1;
    return ((1<<bits)-1)^num;
}

But I’m getting this error when i submit the code.

Line 5: Char 26: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type ‘int’ (solution.cpp)

I get an AC when i use the same logic in Java.