0
0
Swiftprogramming~5 mins

Numeric literal formats in Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A0o
B0x
C0b
DNo prefix, just digits
What does the numeric literal 0b1101 represent in decimal?
A15
B13
C14
D11
How would you write one million in Swift for better readability?
A1000000
B10_00_00
C1_000_000
D1,000,000
What is the value of 3.5e1 in Swift?
A35
B3.5
C350
D0.35
Which of these is NOT a valid numeric literal format in Swift?
A0xFF
B123_456
C0b1010
D0d123
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.