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 <kamranahmed.se@gmail.com>
pull/4952/head^2
Jhonatan Mustiola 5 months ago committed by GitHub
parent 56247431de
commit e9c33a405b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 39
      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)
- [Integer Types](https://rust-book.cs.brown.edu/ch03-02-data-types.html#integer-types)

Loading…
Cancel
Save