Bird
0
0

Which numeric literal correctly represents the decimal number 255 using octal notation in Swift?

easy📝 Conceptual Q2 of 15
Swift - Data Types
Which numeric literal correctly represents the decimal number 255 using octal notation in Swift?
Alet octalValue = 0o255
Blet octalValue = 0o377
Clet octalValue = 0o2F7
Dlet octalValue = 0o400
Step-by-Step Solution
Solution:
  1. Step 1: Recall octal notation rules in Swift

    Octal literals start with 0o and use digits 0-7 only.
  2. Step 2: Convert decimal 255 to octal

    Decimal 255 equals octal 377. let octalValue = 0o377 matches this. let octalValue = 0o255 equals 173 decimal. let octalValue = 0o2F7 has invalid letter F. let octalValue = 0o400 is octal 400 which equals decimal 256.
  3. Final Answer:

    let octalValue = 0o377 -> Option B
  4. Quick Check:

    Octal literal for 255 = 0o377 [OK]
Quick Trick: Octal literals start with 0o and digits 0-7 only [OK]
Common Mistakes:
  • Using digits 8 or 9 in octal literals
  • Confusing octal with decimal or hex
  • Incorrect prefix like 0x instead of 0o

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes