Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the two’s complement of -44?(a) 1011011(b) 11010100(c) 11101011(d) 10110011The question was posed to me in exam.This is a very interesting question from Bitwise in chapter Precedence and Associativity, Bitwise & Boolean of Python

Answer»

Correct OPTION is (B) 11010100

Best 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).

2.

Which of the following expressions can be used to multiply a given number ‘a’ by 4?(a) a4This question was addressed to me in final exam.I need to ask this question from Bitwise in section Precedence and Associativity, Bitwise & Boolean of Python

Answer»

The CORRECT OPTION is (a) a<<2

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.

3.

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) 0I have been asked this question in examination.I'd like to ask this question from Bitwise topic in portion Precedence and Associativity, Bitwise & Boolean of Python

Answer»

Right option is (C) 1

The EXPLANATION is: 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.

4.

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) NOTThis question was addressed to me by my college director while I was bunking the class.The query is from Bitwise in portion Precedence and Associativity, Bitwise & Boolean of Python

Answer»

The CORRECT option is (C) XOR

The explanation: Bitwise XOR gives 1 if either of the BITS is 1 and 0 when both of the bits are 1.

5.

The one’s complement of 110010101 is:(a) 001101010(b) 110010101(c) 001101011(d) 110010100I got this question in final exam.I need to ask this question from Bitwise topic in portion Precedence and Associativity, Bitwise & Boolean of Python

Answer» CORRECT ANSWER is (a) 001101010

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.
6.

The one’s complement of 110010101 is:(a) 001101010(b) 110010101(c) 001101011(d) 110010100I have been asked this question in an interview for job.Question is taken from Bitwise topic in division Precedence and Associativity, Bitwise & Boolean of Python

Answer»
7.

It is not possible for the two’s complement value to be equal to the original value in any case.(a) True(b) FalseI got this question by my college director while I was bunking the class.My question is based upon Bitwise in portion Precedence and Associativity, Bitwise & Boolean of Python

Answer» RIGHT option is (b) False

The explanation is: 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.
8.

Which of the following represents the bitwise XOR operator?(a) &(b) ^(c) |(d) !I have been asked this question by my school principal while I was bunking the class.Asked question is from Bitwise topic in portion Precedence and Associativity, Bitwise & Boolean of Python

Answer»

The correct OPTION is (B) ^

To EXPLAIN: The ^ operator REPRESENT bitwise XOR operation. &: bitwise AND, | : bitwise OR and ! represents bitwise NOT.

9.

Which of the following expressions results in an error?(a) int(1011)(b) int(‘1011’,23)(c) int(1011,2)(d) int(‘1011’)This question was addressed to me by my school principal while I was bunking the class.This interesting question is from Bitwise topic in division Precedence and Associativity, Bitwise & Boolean of Python

Answer»

Correct option is (c) int(1011,2)

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.

10.

To find the decimal value of 1111, that is 15, we can use the function:(a) int(1111,10)(b) int(‘1111’,10)(c) int(1111,2)(d) int(‘1111’,2)I have been asked this question in an interview.Origin of the question is Bitwise in chapter Precedence and Associativity, Bitwise & Boolean of Python

Answer»

The CORRECT choice is (d) int(‘1111’,2)

The best explanation: The expression int(‘1111’,2) GIVES the result 15. The expression int(‘1111’, 10) will give the result 1111.

11.

The expression 2**2**3 is evaluates as: (2**2)**3.(a) True(b) FalseI have been asked this question during a job interview.This question is from Precedence and Associativity topic in division Precedence and Associativity, Bitwise & Boolean of Python

Answer»

Correct answer is (b) False

Easiest explanation - The value of the expression (2**2)**3 = 4**3 = 64. When the expression 2**2**3 is evaluated in python, we GET the result as 256, because this expression is evaluated as 2**(2**3). This is because the associativity of EXPONENTIATION OPERATOR (**) is from right to left and not from left to right.

12.

Which of the following expressions results in an error?(a) float(‘10’)(b) int(‘10’)(c) float(’10.8’)(d) int(’10.8’)I had been asked this question during an interview.This intriguing question comes from Precedence and Associativity in chapter Precedence and Associativity, Bitwise & Boolean of Python

Answer»

The correct ANSWER is (d) INT(’10.8’)

The best I can explain: All of the above examples show EXPLICIT conversion. However the expression int(’10.8’) RESULTS in an ERROR.

13.

Which of the following expressions is an example of type conversion?(a) 4.0 + float(3)(b) 5.3 + 6.3(c) 5.0 + 3(d) 3 + 7I have been asked this question in homework.The query is from Precedence and Associativity topic in chapter Precedence and Associativity, Bitwise & Boolean of Python

Answer» CORRECT answer is (a) 4.0 + float(3)

For EXPLANATION: Type conversion is nothing but explicit conversion of OPERANDS to a SPECIFIC type. Options 5.3 + 6.3 and 5.0 + 3 are examples of implicit conversion whereas OPTION 4.0 + float(3) is an example of explicit conversion or type conversion.
14.

Which of the following expressions involves coercion when evaluated in Python?(a) 4.7 – 1.5(b) 7.9 * 6.3(c) 1.7 % 2(d) 3.4 + 4.6I have been asked this question at a job interview.This intriguing question comes from Precedence and Associativity in portion Precedence and Associativity, Bitwise & Boolean of Python

Answer»

The correct choice is (c) 1.7 % 2

To explain I would say: Coercion is the implicit (AUTOMATIC) conversion of OPERANDS to a common TYPE. Coercion is automatically performed on mixed-type expressions. The expression 1.7 % 2 is evaluated as 1.7 % 2.0 (that is, automatic conversion of int to float).

15.

Which of the following is the truncation division operator?(a) /(b) %(c) //(d) |I got this question in an online interview.The above asked question is from Precedence and Associativity topic in portion Precedence and Associativity, Bitwise & Boolean of Python

Answer»

Right option is (c) //

To explain: // is the operator for TRUNCATION division. It is called so because it returns only the integer part of the quotient, TRUNCATING the decimal part. For EXAMPLE: 20//3 = 6.

16.

Which of the following operators has its associativity from right to left?(a) +(b) //(c) %(d) **This question was posed to me during an interview.The question is from Precedence and Associativity topic in chapter Precedence and Associativity, Bitwise & Boolean of Python

Answer»

Correct answer is (d) **

Easy EXPLANATION - All of the OPERATORS shown above have associativity from LEFT to right, except exponentiation OPERATOR (**) which has its associativity from right to left.

17.

The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same.(a) True(b) FalseThe question was asked by my school teacher while I was bunking the class.My question is based upon Precedence and Associativity in portion Precedence and Associativity, Bitwise & Boolean of Python

Answer»

Correct option is (a) True

Easy explanation - Although the PRESENCE of parenthesis does affect the ORDER of precedence, in the case SHOWN above, it is not making a difference. The result of both of these expressions is 1.333333333. HENCE the statement is true.