Numeric Literals and Underscores
Write binary, hex, and grouped literals for readability.
Numeric Literals
A literal is a value written directly in code, like 42 or 3.14. Swift supports decimal, binary, octal, and hexadecimal integer literals.
let dec = 42
let pi = 3.14
print(dec, pi)Binary Literals
Prefix a literal with 0b to write it in binary. Each digit is a single bit.
let flags = 0b1010
print(flags)
print(0b1111)All lessons in this course
- Integer Types and Their Ranges
- Floating-Point: Double vs Float
- Explicit Numeric Conversions
- Numeric Literals and Underscores