How to remove the lowest order bit in Java

1 Answer

0 votes
public class Main {
    public static void main(String[] args) {
        int n = 2664;

        System.out.println(String.format("%16s", Integer.toBinaryString(n)).replaceAll(" ", "0"));

        n &= (n - 1);
        
        System.out.println(String.format("%16s", Integer.toBinaryString(n)).replaceAll(" ", "0"));
    }
}

  
   
   
/*
run:
  
0000101001101000
0000101001100000
   
*/

 



answered Apr 5, 2024 by avibootz

Related questions

1 answer 111 views
1 answer 99 views
99 views asked Apr 6, 2024 by avibootz
1 answer 115 views
1 answer 120 views
120 views asked Apr 5, 2024 by avibootz
1 answer 155 views
155 views asked Apr 5, 2024 by avibootz
1 answer 147 views
147 views asked Apr 5, 2024 by avibootz
1 answer 132 views
...