Bird
0
0

What is the issue with the following Kotlin code?

medium📝 Debug Q6 of 15
Kotlin - Data Types
What is the issue with the following Kotlin code?
val binaryNum = 0b1102_1010
AThe literal is missing a suffix like 'L' for Long
BUnderscores are not allowed in binary literals
CBinary literals must start with '0x' instead of '0b'
DBinary literals cannot contain the digit '2'
Step-by-Step Solution
Solution:
  1. Step 1: Understand binary literal rules

    Binary literals in Kotlin can only contain digits 0 and 1, optionally separated by underscores.
  2. Step 2: Identify invalid digit

    The digit '2' is invalid in binary literals.
  3. Final Answer:

    Binary literals cannot contain the digit '2' -> Option D
  4. Quick Check:

    Check digits allowed in binary literals [OK]
Quick Trick: Binary literals only use 0 and 1 digits [OK]
Common Mistakes:
MISTAKES
  • Using digits other than 0 or 1 in binary literals
  • Confusing binary prefix '0b' with hexadecimal '0x'
  • Placing underscores at the start or end of the literal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes