[Rust] Integer Types in Rust

This lesson talks about Integer types in Rust and that there are unsigned and signed integers.

It also explains how every the type names are composed of "u" and "i", for unsigned and signed respectively, followed by their with in bits. So u8 is an unsigned integer that can store values up to 8 bits (0 - 255).

#[allow(warnings)]

fn main() {

  // Unsigned integer types:
  //
  // u8:  0 to 2^8  (255)
  // u16: 0 to 2^16 (65,535)
  // u32: 0 to 2^32 (4,294,967,295)
  // u64: 0 to 2^64 (really big number)
  // usize: 0 to 2^32-1 or 2^64-1 


  // Signed integer types:
  //
  // i8:  -2^7 to 2^7-1  (-128 to 127)
  // i16: -2^15 to 2^15-1 (-32,768 to 32,767)
  // i32: -2^31 to 2^31-1 (super negative to super positive)
  // i64: -2^63 to 2^63-1 (you get the idea)
  // isize: -2^31-1 or -2^63-1 to 2^31-1 or 2^63-1


  let number: u8 = 0; 
}

 

posted @   Zhentiw  阅读(3)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2023-02-19 [State Machine] Zag-js
2023-02-19 [React] React hook, component props for refactoring
2020-02-19 【逻辑思维】排中律:生存还是毁灭,只能选一个
2020-02-19 【逻辑思维】矛盾律:谁给理发师理发
2020-02-19 [AST Babel] Create a simple babel plugin
2020-02-19 [Angular 8 Unit testing] Testing a smart component with service injection -- 1
2019-02-19 [React] Ensure all React useEffect Effects Run Synchronously in Tests with react-testing-library
点击右上角即可分享
微信分享提示