Curious why this works
public long flip(long n) {
long finalResult = 0;
for (int i = 0; i < 32; i++) {
finalResult = finalResult | (1L << i);
}
return n ^ finalResult;
}
but this doesn't
public long flip(long n) {
long finalResult = 0;
for (int i = 0; i < 32; i++) {
finalResult = finalResult | (1 << i);
}
return n ^ finalResult;
}
I know that finalResult '11111111111111111111111111111111' will be -1 (and maybe that causes an issue) but i'm still not sure why it causes issues when simply flipping bits in n.