How to get the minimum (min) of two integers with bitwise operators in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        int x = 3;
        int y = -9;            
  
        int n = (x < y == true) ? 1 : 0;
        int min_ = y ^ ((x ^ y) & -(n)); 
        System.out.println(min_);
    }
}


 
/*
run:
 
-9
 
*/

 



answered Mar 23, 2019 by avibootz
...