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:
Step 1: Recall octal notation rules in Swift
Octal literals start with 0o and use digits 0-7 only.
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.
Final Answer:
let octalValue = 0o377 -> Option B
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
Master "Data Types" in Swift
9 interactive learning modes - each teaches the same concept differently