首页 > 其他分享 >[Rust] Integer Types in Rust

[Rust] Integer Types in Rust

时间:2024-02-19 21:34:23浏览次数:35  
标签:u8 32 31 unsigned 63 Rust Integer Types

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; 
}

 

标签:u8,32,31,unsigned,63,Rust,Integer,Types
From: https://www.cnblogs.com/Answer1215/p/18022005

相关文章

  • [Rust] parse().unwrap()
    Thislessonexplains TypeInference inRustandhowitallowsthecompilertofigureoutbyitself,whattypevariableshavewhentheygettheirvaluesassigned.Therearecaseswhenthecompilercannotinferavalue'stypethroughstaticanalysis.I......
  • [Rust] Use Impl with Struct
    useanyhow::{Result,anyhow};usestd::str::FromStr;fnget_input()->&'staticstr{return"0,9->5,98,0->0,89,4->3,42,2->2,17,0->7,46,4->2,00,9->2,93,4->1,40,0->8,85,5->8,2&q......
  • typescript修改target导致模块找不到
    编译ts代码时,发现一个包只支持es6及更高的版本,无奈修改编译选项target,从es5修改为es6,发现原来导入包的地方报错,提示notfound。tsconfig.json{"files":["src/main.ts"],"compilerOptions":{"noImplicitAny":true,"target":......
  • 远程控制软件RustDesk自建服务器全平台部署及使用教程
    RustDesk挺出名的一款远程控制,远程协助的开源软件。完美替代TeamViewer,ToDesk,向日葵等平台。关键支持自建服务器,更安全私密远程控制电脑!其中客户端支持安卓,且支持控制安卓手机。官方地址官网:https://rustdesk.com/开源地址:https://github.com/rustdesk/一、准备工作1,有自己......
  • 教你用Rust实现Smpp协议
    本文分享自华为云社区《华为云短信服务教你用Rust实现Smpp协议》,作者:张俭。协议概述SMPP(ShortMessagePeer-to-Peer)协议起源于90年代,最初由Aldiscon公司开发,后来由SMPP开发者论坛维护和推广。SMPP常用于在SMSC(ShortMessageServiceCenter,短信中心)和短信应用之间传输短消息......
  • VSCOde+Nodejs+Typescript前端开发环境
    1.安装Node.js下载地址:https://nodejs.org/enlts版本:长久稳定版本安装:默认安装就可以了验证:node2.VSCode下载地址:https://code.visualstudio.com/Download安装:默认安装语言切换:安装中文插件,重启 2.1修改终端cmd模式:1.点击设置图标,选择CommandPalette 2.输入:Ter......
  • [Rust] Macros vs. Functions
    InRust,theexclamationmark(!)afteranameindicatesthatitisamacroratherthanafunction.MacrosandfunctionsinRustarecalleddifferentlyandservedifferentpurposes.Macros,likeanyhow!,candothingsthatfunctionscannot,suchasgenera......
  • [Rust] Error handling with Enum
    Wecanuse ReusltenumtodoerrorhandlingtypeResult<V,E>{Err(E),Ok(V)} Example://():empty//uszie:justreturnaintegreaserrorfordemofnerror_me(throw:bool)->Result<(),usize>{ifthrow{returnEr......
  • Rust程序设计 第2版 电子书 pdf
    关注公众号:红宸笑。回复:电子书即可   本书是Rust领域经典参考书,由业内资深系统程序员编写,广受读者好评。书中全面介绍了Rust这种新型系统编程语言——具有无与伦比的安全性,兼具C和C++的高性能,并大大简化了并发程序的编写。第2版对上一版内容进行了重组和完善,新增了对......
  • [Rust] Intro Enum
    GoEnumpackagemaintypeGoEnum=intconst(FooGoEnum=iotaBarBaz)funcmain(){} TypescriptEnumenumTsEnum{Foo,Bar,Baz} RustEnumenumRsEnum{Foo,Bar,Baz}Whygooverenums...Theyaresimple......