Rust for Python Developers - Unsigned, Signed Integers and Casting

Shin_O
33.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:

Unsigned Integer Types

Unsigned integer types in Rust start with u and it has 8, 16, 32, 64, and 128-bit. The minimum and maximum values are from 0 to 2ⁿ-1.

For example u8 has 0 to 2⁸-1, which is 255. The following table shows all the details for unsigned integers.

DATA TYPEMINMAXLength
u802558-bit
u1606553516-bit
u320429496729532-bit
u6401844674407370955161564-bit
u1280340282366920938463463374607431768211455128-bit

If you try to assign a negative number to an unsigned type, it will fail.

- is one of Rust's unary operators and it is the negation operator for signed integer types and floating-point types.

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content