Rust for Python Developers - Unsigned, Signed Integers and Casting

Shin_O
31.6K views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

This story was originally published on Medium

Follow me:

Signed Integer Types

The default integer type in Rust is i32. Signed integer types in Rust start with i and it has 8, 16, 32, 64, and 128-bit.

The minimum and maximum values are from -(2ⁿ⁻¹) to 2ⁿ⁻¹-1. The -1 in the n-1 is the sign bit (positive or negative), which we cover in the next section.

For example i8 has -(2⁷) to 2⁷-1, which is -128 to 127. The following table shows all the details for signed integers.

DATA TYPEMINMAXLength
i8-1281278-bit
i16-327683276716-bit
i32-2147483648214748364732-bit
i64-92233720368547...92233720368547...64-bit
i128-17014118346046923173168...17014118346046923173168...128-bit
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content