- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitShift.java
More file actions
Latest commit
40 lines (32 loc) · 1.78 KB
/
Copy pathBitShift.java
File metadata and controls
40 lines (32 loc) · 1.78 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
packageBit_Manipulation;
importjava.util.Scanner;
classBitShift{
publicstaticvoidmain(String[] args){
Scannersc=newScanner(System.in);
System.out.print("Enter a decimal number: ");
intx=sc.nextInt();
inta=15; //0000 1111
intb=22; //0001 0101
intc=24;
System.out.println("Your numbers "+x+" binary value: "+Integer.toBinaryString(x));
System.out.println(a+" Binary value: "+Integer.toBinaryString(a));
System.out.println(b+" Binary value: "+Integer.toBinaryString(b));
System.out.println(c+" Binary value: "+Integer.toBinaryString(c));
System.out.println("------------------------------------------");
intlshift=a<<1;
System.out.println("left shift Operation : "+lshift+"\t\t Binary value: "+Integer.toBinaryString(lshift));
intrshift=b>>1;
System.out.println("Right shift Operation : "+rshift+"\t\t Binary value: "+Integer.toBinaryString(rshift));
intzshift=c>>>1;
System.out.println("Right shift zero fill Operation : "+zshift+"\t Binary value: "+Integer.toBinaryString(zshift));
System.out.println("------------------------------------------");
intl=x<<1;
System.out.println("left shift Operation on your number: "+l+"\t\t Binary value: "+Integer.toBinaryString(l));
intr=x>>1;
System.out.println("Right shift Operation on your number: "+r+"\t\t Binary value: "+Integer.toBinaryString(r));
intrz=x>>>1;
System.out.println("Right shift zero fill Operation on your number: "+rz+"\t\t Binary value: "+Integer.toBinaryString(rz));
System.out.println("-------------------------------------------");
sc.close();
}
}