This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.
Overview
Opcode: 0x19
Introduced: Frontier (EVM genesis)
NOT performs bitwise NOT (one’s complement) on a 256-bit unsigned integer, inverting every bit (0 becomes 1, 1 becomes 0). This operation is fundamental for bit masking, creating inverted patterns, and logical negation in bitwise contexts.
Primary uses: creating inverse masks, clearing bits (NOT + AND), two’s complement conversion (NOT + 1).
Specification
Stack Input:
Stack Output:
Gas Cost: 3 (GasFastestStep)
Truth Table (per bit):
Behavior
NOT pops one value from the stack, inverts all 256 bits, and pushes the result. The operation is:
- Unary: operates on single operand
- Involutory: ~~a = a (double negation returns original)
- Self-inverse: a XOR (~a) = MAX_UINT256
Result: ~a = MAX_UINT256 - a for unsigned interpretation.
Examples
Basic Inversion
Create Inverse Mask
Zero to Max
Max to Zero
Double Negation (Involution)
Two’s Complement Preparation
Gas Cost
Cost: 3 gas (GasFastestStep)
NOT shares the lowest gas tier with:
- AND (0x16), OR (0x17), XOR (0x18)
- BYTE (0x1a)
- SHL (0x1b), SHR (0x1c), SAR (0x1d)
- ADD (0x01), SUB (0x03)
- Comparison operations
Edge Cases
Alternating Pattern
Single Bit Set
Stack Underflow
Out of Gas
Common Usage
Clear Bits (NOT + AND)
Revoke Permissions
Create Bit Mask
Two’s Complement Negation
Invert Bitmap
Complement in Range Checks
Implementation
Testing
Test Coverage
Edge Cases Tested
- Basic bit inversion
- Zero to MAX_UINT256
- MAX_UINT256 to zero
- Involutory property (~~a = a)
- Alternating bit patterns
- Two’s complement preparation
- Single bit set
- Stack underflow
- Out of gas
Security
Two’s Complement Confusion
Mask Creation Errors
Incorrect Bit Clearing
Signed vs Unsigned
Benchmarks
NOT is one of the fastest EVM operations:
Execution time (relative):
- NOT: 1.0x (baseline, fastest tier)
- AND/OR/XOR: 1.0x (same tier)
- ADD: 1.0x (same tier)
- MUL: 1.2x
- DIV: 2.5x
Gas efficiency:
- 3 gas per 256-bit NOT operation
- ~333,333 NOT operations per million gas
- Native hardware instruction on all platforms
References