Loading [Contrib]/a11y/accessibility-menu.js
Back
Close

Rust for Python Developers - Unsigned, Signed Integers and Casting

Shin_O
1,296 views

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
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants