Bird
0
0

Identify the error in this Kotlin code snippet:

medium📝 Debug Q14 of 15
Kotlin - Data Types
Identify the error in this Kotlin code snippet:
val num = 0b1021_0010
AUnderscores are not allowed in binary literals
BBinary literals cannot contain digits other than 0 or 1
CBinary literals must start with 0x
DThe number is too large for binary format
Step-by-Step Solution
Solution:
  1. Step 1: Understand valid digits in binary literals

    Binary literals can only contain digits 0 and 1, optionally separated by underscores.
  2. Step 2: Check the given literal for invalid digits

    The literal contains '2', which is invalid in binary. Underscores are allowed, and binary literals start with 0b, not 0x.
  3. Final Answer:

    Binary literals cannot contain digits other than 0 or 1 -> Option B
  4. Quick Check:

    Binary digits must be 0 or 1 only [OK]
Quick Trick: Binary digits only 0 or 1, no other digits allowed [OK]
Common Mistakes:
MISTAKES
  • Using digits other than 0 or 1 in binary
  • Confusing hex prefix 0x with binary 0b
  • Thinking underscores are disallowed in binary

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes