Bit masking in Java

How to check the last bits of a number n, in JAVA

I’d use in C++,

if(n&1){// 1}
else{// 0 }

but, In java this doesnt work.

The last bit?

As in, in-

100010111
123456789

Do you want to check the 1 and index 9? If i recall correctly, that 1 adds a total of 2^0=1 in total. So checking if number is odd or even should do i guess.

you can do that by checking whether n is odd or even as vijju said.if n%2==1 then last bit is 1 else last bit is 0.