0Pricing
Zig Academy · Lesson

Arbitrary-Width Integers like u3

Use exact bit-width number types.

Beyond u8 and u32

Zig is not limited to the usual sizes. You can ask for an integer of any bit width, from u1 all the way up to enormous values.

The uN Pattern

Write u followed by a number to get an unsigned integer of exactly that many bits. So u3 holds three bits.

const level: u3 = 5;

All lessons in this course

  1. packed struct for Exact Layout
  2. Arbitrary-Width Integers like u3
  3. Bit Fields and Flags
  4. extern struct and ABI Layout
← Back to Zig Academy