IAE Academy

APTITUDE PRACTICE · PROGRAMMING LOGIC

Operators and number logic: aptitude questions

10 questions for the aptitude round of campus placement tests, each with its answer and working. Try each one before you open the answer.

Companies do not publish their test papers; these questions are ours.

The questions

In the pseudocode, for i = a to b runs i from a up to b, with b included.

  1. QUESTION 1

    In integer arithmetic, gives the quotient and gives the remainder. What is the value of ?

    1. (A)

      9

    2. (B)

      11

    3. (C)

      12

    4. (D)

      2

    Answer and solution

    Answer: (B)

    1. Integer division: 47 / 5 = 9, since 5 x 9 = 45.

    2. Remainder: 47 % 5 = 47 - 45 = 2.

    3. Sum = 9 + 2 = 11.

    4. The answer is B.

  2. QUESTION 2

    What is the value of the expression 12 & 10, where & is bitwise AND on integers?

    1. (A)

      6

    2. (B)

      14

    3. (C)

      8

    4. (D)

      10

    Answer and solution

    Answer: (C)

    1. 12 in binary is 1100 and 10 is 1010.

    2. AND gives 1 only where both bits are 1: 1100 & 1010 = 1000.

    3. 1000 in binary is 8.

    4. The answer is C.

  3. QUESTION 3Type the answer

    Convert the binary number to decimal. Enter the decimal value.

    Answer and solution

    Answer:

    1. Place values from the left are 32, 16, 8, 4, 2, 1.

    2. Bits 101101 select 32, 8, 4 and 1.

    3. 32 + 8 + 4 + 1 = 45.

    4. The answer is 45.

  4. QUESTION 4

    In a C-like language, bitwise & has higher precedence than ^, and ^ has higher precedence than |. What is the value of the following expression?

    9 | 6 & 3 ^ 5
    1. (A)

      15

    2. (B)

      7

    3. (C)

      11

    4. (D)

      13

    Answer and solution

    Answer: (A)

    1. & first: 6 & 3 = 110 & 011 = 010 = 2.

    2. Then ^: 2 ^ 5 = 010 ^ 101 = 111 = 7.

    3. Then |: 9 | 7 = 1001 | 0111 = 1111 = 15.

    4. The answer is A.

  5. QUESTION 5

    What is the hexadecimal form of the decimal number ?

    1. (A)

      96

    2. (B)

      C9

    3. (C)

      9C

    4. (D)

      8C

    Answer and solution

    Answer: (C)

    1. Divide by 16: 156 = 9 x 16 + 12.

    2. The quotient 9 is the higher digit.

    3. The remainder 12 is the hex digit C.

    4. So 156 = 0x9C. The answer is C.

  6. QUESTION 6

    In C, integer division truncates towards zero, and the remainder takes the sign of the dividend. What is the value of -17 % 5?

    1. (A)

      -2

    2. (B)

      2

    3. (C)

      3

    4. (D)

      -3

    Answer and solution

    Answer: (A)

    1. -17 / 5 truncates towards zero to -3.

    2. Remainder = -17 - (-3 x 5) = -17 + 15 = -2.

    3. The remainder has the sign of the dividend, which is negative.

    4. The answer is A.

  7. QUESTION 7Type the answer

    For an integer x, the expression x & (x - 1) is evaluated. If x = 236, what is the value of x & (x - 1)?

    Answer and solution

    Answer:

    1. 236 in binary is 11101100. Subtracting 1 turns the lowest set bit to 0 and the zeros below it to 1, so x - 1 = 235 is 11101011.

    2. AND: 11101100 & 11101011 = 11101000. The expression clears the lowest set bit of x.

    3. 11101000 = 128 + 64 + 32 + 8 = 232.

    4. The answer is 232.

  8. QUESTION 8

    A program runs the following code with 5-bit unsigned values.

    x = 26
    y = x ^ (x >> 1)

    What is the value of y?

    1. (A)

      27

    2. (B)

      13

    3. (C)

      31

    4. (D)

      23

    Answer and solution

    Answer: (D)

    1. 26 in binary is 11010.

    2. x >> 1 = 01101, which is 13.

    3. 11010 ^ 01101 = 10111.

    4. 10111 = 16 + 4 + 2 + 1 = 23. The answer is D.

  9. QUESTION 9

    In C, *, / and % bind tighter than + and -, which bind tighter than <<. All use integer arithmetic and group left to right. What is the value of the following expression?

    7 + 3 * 4 % 5 - 8 / 3 << 1
    1. (A)

      12

    2. (B)

      14

    3. (C)

      7

    4. (D)

      28

    Answer and solution

    Answer: (B)

    1. 3 * 4 % 5 = 12 % 5 = 2.

    2. 8 / 3 = 2 in integer division.

    3. 7 + 2 - 2 = 7.

    4. Shift is last: 7 << 1 = 14. The answer is B.

  10. QUESTION 10Type the answer

    Let v = 0xB7, an 8-bit unsigned value. Compute (v >> 3) ^ 0x0F and enter the result in decimal.

    Answer and solution

    Answer:

    1. 0xB7 in binary is 10110111.

    2. Shifting right by 3 gives 10110, which is 22.

    3. 0x0F is 01111, so 10110 ^ 01111 = 11001.

    4. 11001 = 16 + 8 + 1 = 25.

More practice

More programming logic: Loops and conditions · Functions and recursion · Arrays and strings · Stacks, queues and basic data structures · C language basics

Past GATE aptitude questions, solved: General Aptitude

Every topic with its answers, to print or keep: one PDF (1.9 MB)

All aptitude topics