I am unable to replace all 0 bits with 1
it is giving wrong answer
How to replace all 0 with 1
hello @mohitshendre2609
it is giving correct answer.
it is negative because | (bitwise or) will set the msb bit to 1 as well, due to which our system treats it as a negative number. ( for signed number msb is reserved for signed bit , if it is 1 that means number is negative otherwise number is positive).
msb-> Most significant bit
so how can I replace all the 0 bit with 1
check this.
The number of bits required to represent an integer n is ⌊log2 n ⌋+1.
and what we want is to set all these bit on.
we can do this by 2^(number of bits required)-1.
example if n=2,
then number of bits reuired to write 2 (10 in binary ) is 2 .
using 2^2-1 = 3 (in binary it is 11) clearly all 0 is replaced with 1.
still I am not getting it can you please send me the code of it
check my previous reply