liveBook · Manning

Unsigned integer

As explained in Learn Rust in a Month of Lunches

An unsigned integer type represents nonnegative whole numbers without a sign.

An unsigned integer holds a nonnegative whole number: zero or a positive number, with no decimal point. In Rust, unsigned integer types include u8, u16, u32, u64, u128, and usize. section 1.3

The number in a type such as u8 tells you how many bits it uses. A bit is either 0 or 1. More bits allow larger values: u8 holds up to 255, while u16 holds up to 65,535. section 1.3

fn main() {
    let my_number: u8 = 100;             #1
    println!("{}", my_number as char);
}

This example declares my_number as a u8 and casts it to a character for printing. section 1.3

How Learn Rust in a Month of Lunches covers it

How deep it goes
Explains bit widths, binary digits, and selected maximum values, with a brief character-casting example.
Examples
Uses u8 and u16 maximum values and a u8 variable cast to a character.
What you can do after
Evaluate unsigned integer types by their nonnegative ranges and bit widths.
How it connects
Connects unsigned integers with signed integers, binary representation, and character casting.

Also explained in

Compare how 9 books explain unsigned integer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Rust in a Month of Lunches. The section links point to the parts of the book it draws on.