Recall & Review
beginner
What is a numeric literal in Swift?
A numeric literal is a fixed number value written directly in code, like 42 or 3.14.
Click to reveal answer
beginner
How do you write a binary literal in Swift?
Use the prefix
0b followed by 0s and 1s, for example: 0b1010 equals 10 in decimal.Click to reveal answer
beginner
What prefix is used for hexadecimal literals in Swift?
Hexadecimal literals start with
0x, like 0x1F which equals 31 in decimal.Click to reveal answer
beginner
How can you write a number with underscores in Swift and why?
You can add underscores to separate digits for readability, like
1_000_000. It helps you read large numbers easily but does not affect the value.Click to reveal answer
intermediate
How do you write a floating-point literal with an exponent in Swift?
Use
e or E to indicate the power of 10, for example: 1.25e2 means 1.25 × 10² = 125.Click to reveal answer
Which prefix is used for octal literals in Swift?
✗ Incorrect
Swift uses
0o as the prefix for octal literals, like 0o17.What does the numeric literal
0b1101 represent in decimal?✗ Incorrect
0b1101 is binary for 13 in decimal.How would you write one million in Swift for better readability?
✗ Incorrect
Using underscores like
1_000_000 improves readability without changing the value.What is the value of
3.5e1 in Swift?✗ Incorrect
3.5e1 means 3.5 × 10¹, which equals 35.Which of these is NOT a valid numeric literal format in Swift?
✗ Incorrect
0d is not a valid prefix in Swift; decimal literals have no prefix.Explain the different numeric literal formats available in Swift and give an example of each.
Think about prefixes like 0b, 0o, 0x and how floating-point numbers use e for exponents.
You got /6 concepts.
How do underscores improve numeric literals in Swift? Provide an example.
Consider readability and whether underscores change the number.
You got /3 concepts.