How to get the value of the lowest (rightmost) one bit of a number in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        long num = 124; // 111 1100 // 1 ^ 2 = 4
        
        System.out.println("Lowest one bit = " + Long.lowestOneBit(num));
    }
}



/*
run:

Lowest one bit = 4

*/

 



answered Nov 25, 2022 by avibootz

Related questions

1 answer 108 views
1 answer 111 views
1 answer 115 views
1 answer 121 views
1 answer 163 views
1 answer 174 views
1 answer 147 views
...