Clear Bit operation || Bit manipulation in java language.

 ■ input->

import java.util.*;

public class Bits {

public static void main(String args[]) {

Scanner sc=new Scanner(System.in);

System.out.println("Enter a number=");

int n = sc.nextInt();

System.out.println("Enter a position=");    

int pos=sc.nextInt();

int bitMask = 1<<pos;

int newBitMask = ~(bitMask);

int newNumber = newBitMask & n;

System.out.println("after operation the number is=");     

System.out.println(newNumber);

}

}

■ Output->

Enter a number= 5

Enter a position= 2

after operation the number is= 1

Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.