Contents

Which of the following expressions results in an error?
a) int(1011)                          
b) int(‘1011’,23)
c) int(1011,2)                      
d) int(‘1011’)

c

Explanation: The expression int(1011,2) results in an error. Had we written this expression as int(‘1011’,2), then there would not be an error.


Which of the following represents the bitwise XOR operator?
a) &                                       
b) ^
c) |                                                          
d) !

b

Explanation: The ^ operator represent bitwise XOR operation. &: bitwise AND, | : bitwise OR and ! represents bitwise NOT.


What is the value of the following Python expression?               bin(0x8)
a) ‘0bx1000’                       
b) 8
c) 1000                                 
d) ‘0b1000’

d

Explanation: The prefix 0x specifies that the value is hexadecimal in nature. When we convert this hexadecimal value to binary form, we get the result as: ‘0b1000’.


What will be the output of the following Python expression?     0x35 | 0x75
a) 115                                   
b) 116
c) 117                                    
d) 118

c

Explanation: The binary value of 0x35 is 110101 and that of 0x75 is 1110101. On OR-ing these two values we get the output as: 1110101, which is equal to 117. Hence the result of the above expression is 117.


It is not possible for the two’s complement value to be equal to the original value in any case.
a) True                                  
b) False

b

Explanation: In most cases the value of two’s complement is different from the original value. However, there are cases in which the two’s complement value may be equal to the original value. For example, the two’s complement of 10000000 is also equal to 10000000. Hence the statement is false.


The one’s complement of 110010101 is:
a) 001101010                     
b) 110010101
c) 001101011                      
d) 110010100

a

Explanation: The one’s complement of a value is obtained by simply changing all the 1’s to 0’s and all the 0’s to 1’s. Hence the one’s complement of 110010101 is 001101010.