Unset least significant K bits of a given number | Java program for the above approach ; Function to return the value after unsetting K LSBs ; Create a mask ; Bitwise AND operation with the number and the mask ; Driver Code ; Given N and K ; Function Call
import java . util . * ; class GFG { static int clearLastBit ( int N , int K ) { int mask = ( - 1 << K + 1 ) ; return N = N & mask ; } public static void main ( String [ ] args ) { int N = 730 , K = 3 ; System . out . print ( clearLastBit ( N , K ) ) ; } }