Bird
0
0

What is the output of the following Swift code?

medium📝 Predict Output Q4 of 15
Swift - Data Types
What is the output of the following Swift code?
let number = 0b1010_1101
print(number)
A173
B10101101
C0b10101101
DError: Invalid binary literal
Step-by-Step Solution
Solution:
  1. Step 1: Understand binary literals with underscores

    Binary literals start with 0b and can include underscores for readability.
  2. Step 2: Convert binary 10101101 to decimal

    Binary 10101101 equals decimal 173. Underscores are ignored.
  3. Final Answer:

    173 -> Option A
  4. Quick Check:

    Binary literal 0b1010_1101 = 173 [OK]
Quick Trick: Underscores in literals improve readability, ignored in value [OK]
Common Mistakes:
  • Printing the literal as a string instead of its value
  • Misinterpreting underscores as part of the number
  • Confusing binary with decimal output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes