Set 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 newNumber = bitMask | n;
System.out.println("after operation the number is=");
System.out.println(newNumber);
}
}
■》Output->
enter a number= 5
enter a position= 1
after operation the number is= 7
Comments
Post a Comment