<span class="greencolor2">Enrol for Java Certification</span>
Certifications Boost Confidence. Go through Certifications CENTER
Study and learn Java MCQ Questions and Answers on Bitwise Operators and their priorities. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save As PDF option next using a Google Chrome browser or any other browser.
Go through Java Theory Notes on Bitwise Operators before reading the questions.
!
&
~
It negates the bit 1 to 0 and bit 0 to 1.
&, &=
|, |=
^, ^=
Logical & is used here. (a>5) & (b<10)
Left shift operator shifts individual bits from right side to the left side.
Right Shift operator shifts individual bits of a number from left side to the right side maintaining the sign of the number. So, a negative number is still a negative number after the right shift operation.
>>> (Right Shift Fill Zero) operator fills the left side gaps created by shifting with Zeros thus losing the sign of the number.
byte a = 0b0000_0001; //1 a = a << 1; //a now holds 0000_0010 //2
byte a = 0b0000_0100; //4 a = a >> 1; //a now holds 0000_0010 i.e 2
byte a = 0b0000_0001; System.out.println(~a);
a = 0b0000_0001; //1 ~a = 1111_1110; //254 Byte rannge is -128 to +127. So, overflown 255 goes to the negative side
int b=45; String str=""; while(b > 0) { str = str + b%2; b = b/2; } StringBuilder sb = new StringBuilder(str); sb.reverse(); System.out.println(sb.toString());
The output is 101101 (45).
System.out.println(0b0000_1000);
Binary literals start with 0b. Above number is 8 in decimal notation.
1 & 1 = 1
1 | 1 = 1
0 & (anything) = 0
1 | (anything) = 1
1 & (P) = 1 if P=1 1 & (P) = 0 if P=0
0 | P = 1 if P==1 0 | P = 0 if P==0
0 ^ 0 = 0; 1 ^ 1 = 1;
0 ^ 1 = 1; 1 ^ 0 = 1;
Open Certification Helper Popup Reset Popup