2. Integers

by gg582 · 2026-05-23 11:15:02 · 40 views

All those pretty little 'Integers'

Type Size
u8 0—255
i8 -128—127
u16 0—65535
i16 -32768—32767
i32 -2^{31}2^{31}-1
i64 -2^{63}2^{63}-1
i128 -2^{127}2^{127}-1

Formations?

Formation Expression
2 0b
8 0o
16 0x

Print via println! Macro

fn main() {
    let default_int = 42;
    let unsigned_8: u8 = 255;
    let signed_16: i16 = -32768;

    println!("All in println! macro: {} {} {}", default_int, unsigned_8, signed_16);

    let byte_val = 0b1111_0000;
    let octal_val = 0o77;
    let hex_val = 0xff;
    let explicit_u32 = 100u32;

    println!("Various expressions: {} {} {} {}", byte_val, octal_val, hex_val, explicit_u32);
}

Notes

{} and a macro? That's fine.

And so on...

  • float
  • double
Back

Comments

No comments yet.