Bird
0
0

What is the output of this Kotlin code?

medium📝 Predict Output Q4 of 15
Kotlin - Data Types
What is the output of this Kotlin code?
val a = 0x1A
val b = 0b1101
println(a + b)
A39
B27
C31
DInvalid syntax
Step-by-Step Solution
Solution:
  1. Step 1: Convert hexadecimal and binary literals to decimal

    0x1A in hex is 26 decimal. 0b1101 in binary is 13 decimal.
  2. Step 2: Add the decimal values

    26 + 13 = 39.
  3. Final Answer:

    39 -> Option A
  4. Quick Check:

    Hex + Binary sum = 39 [OK]
Quick Trick: Convert hex and binary to decimal before adding [OK]
Common Mistakes:
MISTAKES
  • Confusing hex 0x1A as 1A decimal
  • Misreading binary 0b1101 as 1101 decimal
  • Assuming syntax error due to underscores

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes