Bitwise……… gives 1 if either of the bits is 1 and 0 when both of the bits are 1.
a) OR
b) AND
c) XOR
d) NOT
Explanation: Bitwise XOR gives 1 if either of the bits is 1 and 0 when both of the bits are 1.
What will be the output of the following Python expression? 4^12
a) 2
b) 4
c) 8
d) 12
Explanation: ^ is the XOR operator. The binary form of 4 is 0100 and that of 12 is 1100. Therefore, 0100^1100 is 1000, which is equal to 8.
Any odd number on being AND-ed with…….. always gives 1. Hint: Any even number on being AND-ed with this value always gives 0.
a) 10
b) 2
c) 1
d) 0
Explanation: Any odd number on being AND-ed with 1 always gives 1. Any even number on being AND-ed with this value always gives 0.
What will be the value of the following Python expression?
bin(10-2)+bin(12^4)
a) 0b10000
b) 0b10001000
c) 0b1000b1000
d) 0b10000b1000
Explanation: The output of bin(10-2) = 0b1000 and that of bin(12^4) is ob1000. Hence the output of the above expression is: 0b10000b1000.
Which of the following expressions can be used to multiply a given number ‘a’ by 4?
a) a<<2
b) a<<4
c) a>>2
d) a>>4
Explanation: Let us consider an example wherein a=2. The binary form of 2 is 0010. When we left shift this value by 2, we get 1000, the value of which is 8. Hence if we want to multiply a given number ‘a’ by 4, we can use the expression: a<<2.
What is the two’s complement of -44?
a) 1011011
b) 11010100
c) 11101011
d) 10110011
Explanation: The binary form of -44 is 00101100. The one’s complement of this value is 11010011. On adding one to this we get: 11010100 (two’s complement).