Bird
0
0

Which of the following is a valid binary numeric literal in Swift?

easy📝 Conceptual Q11 of 15
Swift - Data Types
Which of the following is a valid binary numeric literal in Swift?
A<code>0b1010</code>
B<code>0x1010</code>
C<code>1010b</code>
D<code>0o1010</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand binary literal format in Swift

    Binary literals start with 0b followed by 0s and 1s.
  2. Step 2: Check each option

    0b1010 uses 0b prefix correctly. 0x1010 is hexadecimal, C is invalid, A is octal.
  3. Final Answer:

    0b1010 -> Option A
  4. Quick Check:

    Binary literals start with 0b = D [OK]
Quick Trick: Binary literals always start with 0b prefix [OK]
Common Mistakes:
  • Confusing binary (0b) with hexadecimal (0x)
  • Placing the b suffix after the number
  • Using octal prefix 0o for binary

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes