From e9c33a405b38db078ed4ee34b269306305915629 Mon Sep 17 00:00:00 2001 From: Jhonatan Mustiola <152746443+hiahir357@users.noreply.github.com> Date: Fri, 10 May 2024 20:53:54 -0400 Subject: [PATCH] Update rust integers section (#4821) * Update 100-integers.md More readable, links and more explanations were added * Update 100-integers.md Changes in the way the links were coded * Update 100-integers.md Incorrect wording corrected * Update 100-integers.md Incorrect markdown format corrected * Update 100-integers.md Incorrect line spacing was corrected and "-" sign was prepended to each link item --------- Co-authored-by: Jhonatan Mustiola <152746443+JhonatanMustiolaCas@users.noreply.github.com> Co-authored-by: Kamran Ahmed --- .../103-data-structures/100-integers.md | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/data/roadmaps/rust/content/101-language-basics/103-data-structures/100-integers.md b/src/data/roadmaps/rust/content/101-language-basics/103-data-structures/100-integers.md index 83ea6f025..9e4cab2a2 100644 --- a/src/data/roadmaps/rust/content/101-language-basics/103-data-structures/100-integers.md +++ b/src/data/roadmaps/rust/content/101-language-basics/103-data-structures/100-integers.md @@ -1,7 +1,42 @@ # Integers -In Rust, integers are a primitive data type that hold whole number values, both positive and negative. Integer types in Rust can be divided into two subcategories: signed and unsigned. Signed integers are those that can hold negative, zero, and positive values whereas unsigned integers only hold zero and positive values. They are denoted by "i" and "u" respectively followed by a number which represents the number of bits they occupy in memory. The available integer types are `i8`, `i16`, `i32`, `i64`, `i128` and `isize` (signed), and `u8`, `u16`, `u32`, `u64`, `u128` and `usize` (unsigned). In these types, the number after "i" or "u" denotes the size of the integer type in bits. The `isize` and `usize` types depend on the kind of computer your program is running on: 64 bits on a 64-bit architecture and 32 bits on a 32-bit architecture. +In Rust, integers are a primitive data type that hold whole number values, both positive and negative. Integer types in Rust can be divided into signed and unsigned ones: + +- Signed integers, denoted by "i", are those that can hold negative, zero, and positive values +- Unsigned integers, denoted by "u" only hold zero and positive values. + +Each denotation is followed by a number which represents the number of bits they occupy in memory. The available integer types are: + +|Type|Minimum|Maximum| +|---|---|---| +|i8|-(2^7)|(2^7)-1| +|i16|-(2^15)|(2^15)-1| +|i32|-(2^31)|(2^31)-1| +|i64|-(2^63)|(2^63)-1| +|i128|-(2^127)|(2^127)-1) +|isize|-(2^31) or -(2^63)|(2^31)-1 or (2^63)-1| + +The unsigned integer types consist of: + +|Type|Minimum|Maximum| +|---|---|---| +|u8|0|(2^8)-1| +|u16|0|(2^16)-1| +|u32|0|(2^32)-1| +|u64|0|(2^64)-1| +|u128|0|(2^128)-1| +|usize|0|(2^32)-1 or (2^64)-1| + +In these types, the number after "i" or "u" denotes the size of the integer type in bits. + +There're also the `isize` and the `usize` integer types. The sizes of these primitive are taken from the computer architecture (32/64 bits). When one these types is declared, the compiler calculate, so to speak, how many bytes it takes to reference any location in memory. For example, on a 32 bit target, this is 4 bytes and on a 64 bit target, this is 8 bytes. + +- [Integer Data Type in Rust](https://doc.rust-lang.org/book/ch03-02-data-types.html#integer-types) + +- [Rust Data Types (With Examples)](https://www.programiz.com/rust/data-types#integer-type) + +- [Machine-dependent Integer Types](https://doc.rust-lang.org/reference/types/numeric.html#machine-dependent-integer-types) Learn more from the following links: -- [Integer Types](https://rust-book.cs.brown.edu/ch03-02-data-types.html#integer-types) \ No newline at end of file +- [Integer Types](https://rust-book.cs.brown.edu/ch03-02-data-types.html#integer-types)