Skip to main content

Try it Live

Run Uint examples in the interactive playground
Conceptual Guide - For API reference and method documentation, see Uint API.
Unsigned integers are non-negative whole numbers used throughout Ethereum for amounts, balances, timestamps, and more. This guide teaches uint fundamentals using Tevm.

What Are Unsigned Integers?

An unsigned integer is a whole number (0, 1, 2, 3, …) with no negative values. The EVM uses unsigned integers for:
  • Token amounts and balances
  • Gas prices and limits
  • Block numbers and timestamps
  • Nonces and counters
  • Storage slot indices

EVM Integer Types

The EVM supports unsigned integers from 8 to 256 bits in 8-bit increments:

Why uint256?

Most Ethereum operations use uint256 (32 bytes) because:
  • EVM stack operates on 256-bit words
  • Efficient for large numbers (token amounts, wei)
  • Storage slots are 32 bytes
  • Cryptographic operations use 256-bit values

Creating Uints

Big-Endian Encoding

The EVM stores unsigned integers in big-endian format: most significant byte first.
This matches EVM memory/storage layout and ABI encoding.

Arithmetic Operations

All arithmetic wraps on overflow (mod 2^256), matching EVM behavior:

Comparisons

Bitwise Operations

Size Variants and Padding

While Tevm focuses on uint256, you can work with smaller sizes:

Common Use Cases

JavaScript Number Limitations

CRITICAL: JavaScript numbers are 64-bit floats, only precise up to 2^53-1 (9,007,199,254,740,991).

Conversions

Resources

Next Steps