- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckBitSet.java
More file actions
Latest commit
26 lines (22 loc) · 641 Bytes
/
Copy pathcheckBitSet.java
File metadata and controls
26 lines (22 loc) · 641 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
packageBit_Manipulation;
importjava.util.Scanner;
publicclasscheckBitSet {
publicstaticvoidmain(String... args){
Scannersc=newScanner(System.in);
System.out.print("Enter the Number: ");
intnum=sc.nextInt();
System.out.print("Position to check: ");
intpos=sc.nextInt();
System.out.println("Your number is: "+Integer.toBinaryString(num));
if(!checkBit(num,pos)){
System.out.println("The "+pos+" bit is set(or 1). ");
}else{
System.out.println("The "+pos+" bit is not set(or 0).");
}
sc.close();
}
staticbooleancheckBit(intn,intp){
booleanres=((n&(1<<p))==0)?true:false;
returnres;
}
}