Try it Live
Run Int examples in the interactive playground
Int16
Type-safe signed 16-bit integers with two’s complement encoding and EVM SDIV/SMOD semantics.Overview
Brandednumber type representing signed 16-bit integers (-32768 to 32767). Uses two’s complement representation for negative values and implements EVM signed division/modulo semantics.
Quick Start
- Basic Operations
- Two's Complement
- EVM Semantics
- Comparison & Sign
Two’s Complement Encoding
Negative values use two’s complement representation:| Decimal | Hex | Binary | Notes |
|---|---|---|---|
| 32767 | 0x7FFF | 0111111111111111 | INT16_MAX |
| 1 | 0x0001 | 0000000000000001 | Positive |
| 0 | 0x0000 | 0000000000000000 | Zero |
| -1 | 0xFFFF | 1111111111111111 | All bits set |
| -32768 | 0x8000 | 1000000000000000 | INT16_MIN (sign bit) |
- 0 = positive (0 to 32767)
- 1 = negative (-32768 to -1)
EVM SDIV/SMOD Semantics
Signed Division (SDIV)
Truncates toward zero (not toward negative infinity):Signed Modulo (SMOD)
Sign follows the dividend (first operand):Overflow Handling
All operations check for overflow:Arithmetic Right Shift
shiftRight preserves the sign bit (arithmetic shift):
Bitwise Operations
Bitwise operations work on two’s complement representation:Constructors
Conversions
Validation
Related
- Int8 - Signed 8-bit integers (-128 to 127)
- Uint - Unsigned 256-bit integers
- Opcode - EVM instructions (SDIV, SMOD)
References
- EVM SDIV - Signed division opcode
- EVM SMOD - Signed modulo opcode
- Two’s Complement - Wikipedia

