0Pricing
Zig Academy · Lesson

Sized Integers: i32, u8, usize

Pick the exact width you need.

Sized Integers: i32, u8, usize is a free Zig Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Zig Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Integers Carry Their Size

In Zig the width of an integer is part of its type. You always know exactly how many bits a number uses. 🔢

Signed Integers Start with i

A type like i32 is a signed 32-bit integer. The i means it can hold negative values as well as positive ones.

const temperature: i32 = -15;

Unsigned Integers Start with u

An u8 is an unsigned 8-bit integer. With no sign bit it stores only non-negative values, from 0 up to 255.

const level: u8 = 200;

Pick the Width You Need

The number after i or u is the bit width. A u8 covers 0 to 255, while a u16 reaches all the way up to 65535.

usize for Sizes and Indexes

The usize type is an unsigned integer sized to hold any memory address or index on your machine. Use it for lengths.

const count: usize = 42;

isize Is Its Signed Cousin

The isize type matches usize in width but is signed. Reach for it when an index-sized value can also go negative.

Why Explicit Sizes Help

Fixed widths make memory and overflow predictable. You never have to guess how big an int is on a given platform.

Annotate or Let Zig Infer

You can label a value with a type, or let Zig infer it from context. A bare literal often becomes a comptime integer.

const x: i32 = 100;
const y = 7;

Values Must Fit the Type

Zig refuses to store a value that does not fit. Assigning 300 to a u8 is a compile error, since u8 stops at 255.

Convert Widths with @intCast

To move between integer widths you ask explicitly. The @intCast built-in converts a value to a different integer type.

const big: u32 = 250;
const small: u8 = @intCast(big);

Read the Range in the Name

The name tells you everything: i8 ranges from -128 to 127, while u16 spans 0 to 65535. The width and sign are right there.

Quick Check

You need a value that stores the length of an array or a memory index. Which integer type is the natural fit?

Recap

Zig integers name their sign and width: i32, u8, and usize. Pick the smallest type that fits, and cast on purpose when widths differ. 🎯

Frequently asked questions

Is the “Sized Integers: i32, u8, usize” lesson free?

Yes — the full text of “Sized Integers: i32, u8, usize” is free to read here on the web, and the Zig Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Zig Academy course, upgrade to CoddyKit PRO.

What will I learn in “Sized Integers: i32, u8, usize”?

Pick the exact width you need. You practise Zig Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Zig Academy?

No prior experience is required. Zig Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Sized Integers: i32, u8, usize” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Zig Academy lesson?

Yes. Every Zig Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Sized Integers: i32, u8, usize
  2. Floating Point: f32 and f64
  3. bool, void, and the Comptime Types
  4. Number Literals and Underscores
← Back to Zig Academy