0Pricing
Swift Academy · Lesson

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

  1. Integer Types and Their Ranges
  2. Floating-Point: Double vs Float
  3. Explicit Numeric Conversions
  4. Numeric Literals and Underscores
← Back to Swift Academy