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
- packed struct for Exact Layout
- Arbitrary-Width Integers like u3
- Bit Fields and Flags
- extern struct and ABI Layout