Back
Close

Rust for Python Developers - Unsigned, Signed Integers and Casting

Shin_O
31.5K views

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.

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