Test Series - java

Test Number 24/64

Q: What is the output of a Bitwise Exclusive OR (^) operation if both the inputs/operands are different?
A. 0
B. 1
C. 0 or 1
D. None of the above
Solution: 0 ^ 1 = 1;
1 ^ 0 = 1;
Q: What does this Java code snippet prints?
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());
A. Prints the remainder of a number
B. Prints Binary representation of a number
C. Prints Octal representation of a number
D. Prints Hexadecimal representation of a number
Solution: The output is 101101 (45).
Q: What is the output of a Bitwise OR (|) operation if one of the inputs/operands is 0?
A. 0
B. 1
C. 0 or 1
D. None of the above
Solution: 0 | P = 1 if P==1
0 | P = 0 if P==0
Q: What is the output of the Java code snippet?
System.out.println(0b0000_1000);
A. 0b0000_1000
B. 1000
C. 8
D. 9
Solution: Binary literals start with 0b. Above number is 8 in decimal notation.
Q:  What is the output of a Bitwise AND (&) operation if both the inputs/operands are 1s?
A. 0
B. 1
C. 0 or 1
D. None of the above
Solution: 1 & 1 = 1
Q: What is the output of a Bitwise Exclusive OR (^) operation if both of the inputs/operands are 0s or 1s?
A. 0
B. 1
C. 0 or 1
D. None of the above
Solution: 0 ^ 0 = 0;
1 ^ 1 = 1;
Q: What is the output of a Bitwise AND (&) operation if one of the inputs/operands is 1?
A. 0
B. 1
C. 0 or 1
D. None of the above
Solution: 1 & (P) = 1 if P=1
1 & (P) = 0 if P=0
Q: What is the output of a Bitwise OR (|) operation if one of the inputs/operands is 1?
A. 0
B. 1
C. 0 or 1
D. None of the above
Solution: 1 | (anything) = 1
Q: What is the output of a Bitwise AND (&) operation if one of the inputs/operands is 0?
A. 0
B. 1
C. 0 or 1
D. None of the above
Solution: 0 & (anything) = 0
Q: What is the output of a Bitwise OR (|) operation if both the inputs are 1s?
A. 0
B. 1
C. 0 or 1
D. None of the above
Solution: 1 | 1 = 1

You Have Score    /10