Solidity Math Course

Learn Solidity math concepts through interactive lessons

Lessons

Lesson 1: Valid Uint Sizes

Learn about unsigned integers and their supported bit sizes in Solidity.

Start Lesson

Lesson 2: Maximum Integer Size

Learn how to calculate the maximum values that different uint types can store.

Start Lesson

Lesson 3: Smallest Number of Bits Required to Hold a Number

Learn how to calculate the minimum uint size needed to store specific values.

Start Lesson

Lesson 4: Overflow Due to Addition

Learn how to prevent overflow when adding values in Solidity.

Start Lesson

Lesson 5: Overflow Due to Multiplication

Learn how to calculate maximum values to prevent multiplication overflow.

Start Lesson

Lesson 6: Overflow Due to Exponentiation

Learn how to calculate maximum exponents to prevent overflow in power operations.

Start Lesson

Lesson 7: Solidity Upcasting Rule

Learn how Solidity determines the result type when combining different uint sizes.

Start Lesson

Lesson 8: Maximum Value on Addition and Multiplication

Learn to calculate maximum return values considering both operation and return type limits.

Start Lesson

Lesson 9: Uint Sizes of Constants

Learn how Solidity automatically assigns uint sizes to constants and their impact on operations.

Start Lesson

Lesson 10: Division of Unsigned Integers

Learn how integer division works in Solidity and why it always rounds down.

Start Lesson

Lesson 11: Modulus

Learn how to calculate remainders using the modulus operator in Solidity.

Start Lesson

Lesson 12: Modulus to Detect Divisibility

Learn how to use modulus to check if numbers are divisible and write boolean conditions.

Start Lesson

Lesson 13: Units of Time

Learn how Solidity's time unit suffixes work and their conversion to seconds.

Start Lesson

Lesson 14: Units of Ether

Learn how Solidity's Ether unit suffixes work and their conversion to wei.

Start Lesson

Lesson 15: Scientific Notation

Learn how to use scientific notation (1e18) for large numbers in Solidity.

Start Lesson

Lesson 16: Rounding Down Disallowed Constants

Learn how to fix compilation errors when dividing constants that don't result in exact integers.

Start Lesson

Lesson 17: Rounding Up Disallowed Constants

Learn how to round constants up to the next valid value when division doesn't result in exact integers.

Start Lesson

Lesson 18: Coefficients with decimals

Learn how Solidity allows decimal coefficients as long as the final result is a whole number.

Start Lesson

Lesson 19: Division Rounding Up

Learn how to implement division that rounds up to the next integer instead of truncating.

Start Lesson

Lesson 20: Upcasting with time and ether suffixes

Learn how time and ether suffixes affect type upcasting and overflow calculations.

Start Lesson

Lesson 21: Unchecked overflow

Learn how unchecked blocks allow arithmetic overflow and how to calculate the resulting values.

Start Lesson

Lesson 22: Year to overflow for timestamps

Learn to calculate when timestamps stored in different uint types will overflow in the future.

Start Lesson

Lesson 23: Year to overflow for linearly increasing values

Learn to calculate uint sizes needed for values that grow linearly over time in DeFi applications.

Start Lesson

Lesson 24: Unchecked underflow

Learn how unchecked blocks allow arithmetic underflow and how to calculate the resulting values.

Start Lesson

Lesson 25: Order of Operations 1

Learn how Solidity follows mathematical order of operations with parentheses, exponents, and left-to-right evaluation.

Start Lesson

Lesson 26: Percentage Increases

Learn how to calculate percentage increases in Solidity using integer multiplication and division.

Start Lesson

Lesson 27: Time to overflow for compounding values

Learn to calculate when compounding interest trackers will overflow in lending protocols using logarithmic formulas.

Start Lesson

Lesson 28: Postfix Operators

Learn how to use the ++ and -- operators to increment and decrement variables, including overflow behavior.

Start Lesson

Lesson 29: Signed integer max value

Learn how to calculate the maximum positive values that different signed integer types can store.

Start Lesson

Lesson 30: Signed Integer Minimum Value

Learn how to calculate the minimum negative values that different signed integer types can store.

Start Lesson

Lesson 31: Downcasting

Learn about safe and unsafe type casting, and how to determine maximum values for safe downcasting between different uint sizes.

Start Lesson

Lesson 32: Downcasting is the same as modulo 2ⁿ

Learn how downcasting operations are mathematically equivalent to modulo operations and how to calculate the resulting values.

Start Lesson

Lesson 33: Return value from postfix operators

Learn how postfix operators (++ and --) return the value before increment/decrement and how to work with their dual behavior.

Start Lesson

Lesson 34: Hexadecimal Numbers

Learn how to convert hexadecimal numbers to decimal using base-16 positional notation and hexadecimal digit values.

Start Lesson

Lesson 35: Maximum uint size in hexadecimal

Learn how to express maximum uint values in hexadecimal notation using the relationship between bits, bytes, and 0xff patterns.

Start Lesson

Fixed Point Numbers

Lesson 36: Scaling Factors for Fixed Point Numbers

Learn how scaling factors work in fixed-point arithmetic and how to convert between stored and interpreted values.

Start Lesson

Lesson 37: Adding fixed-point numbers with the same scaling factor

Learn how to add fixed-point numbers by simply adding their stored values when they share the same scaling factor.

Start Lesson

Lesson 38: Converting an integer to a fixed-point number

Learn how to convert integers to fixed-point representation by multiplying with the scaling factor.

Start Lesson

Lesson 39: Converting a fixed-point number to an integer

Learn how to convert fixed-point numbers back to integers by dividing by the scaling factor and truncating decimals.

Start Lesson

Lesson 40: Adding an integer to a fixed-point number to get a fixed-point number

Learn how to add integers to fixed-point numbers by first converting the integer to fixed-point representation.

Start Lesson

Lesson 41: Adding an integer to a fixed-point number to get an integer

Learn how to add integers to fixed-point numbers by first converting the fixed-point number to an integer.

Start Lesson

Lesson 42: Increasing the scale of a fixed-point number

Learn how to increase the scaling factor of fixed-point numbers by multiplying with the appropriate ratio.

Start Lesson

Lesson 43: Decreasing the scaling factor

Learn how to decrease the scaling factor of fixed-point numbers by dividing with the appropriate ratio.

Start Lesson

Lesson 44: Adding fixed-point numbers with unequal scaling factors

Learn how to add fixed-point numbers with different scaling factors by normalizing them to a common scale.

Start Lesson

Lesson 45: Largest fixed-point number representable in a uint

Learn how to calculate the maximum value that can be represented by different uint types with various scaling factors.

Start Lesson

Multiplication and Division of Fixed-Point Numbers

Lesson 46: Multiplying fixed-point numbers with the same scaling factor

Learn how to multiply fixed-point numbers with matching scaling factors and handle the result scaling.

Start Lesson

Lesson 47: Smallest value a fixed-point number can represent

Learn how to determine the precision limit of fixed-point numbers based on their scaling factor.

Start Lesson

Lesson 48: Fixed-point multiplication rounding up

Learn how to implement multiplication that rounds up instead of truncating for improved precision.

Start Lesson

Lesson 49: Multiplying fixed-point numbers with integers

Learn how to multiply fixed-point numbers by integers without changing the scaling factor.

Start Lesson

Lesson 50: Multiplying fixed-point numbers with unequal scaling factors

Learn how to multiply fixed-point numbers that have different scaling factors.

Start Lesson

Lesson 51: Dividing fixed-point numbers with the same scaling factor

Learn how to divide fixed-point numbers with matching scaling factors correctly.

Start Lesson

Lesson 52: Dividing fixed-point numbers with integers

Learn how to divide fixed-point numbers by integers while maintaining precision.

Start Lesson

Lesson 53: Integers divided by integers to produce fixed-point numbers

Learn how to divide integers to create fixed-point results with proper scaling.

Start Lesson

Lesson 54: Integers divided by fixed-point numbers

Learn how to divide integers by fixed-point numbers to produce fixed-point results.

Start Lesson

Lesson 55: Dividing fixed-point numbers with unequal scaling factors

Learn how to divide fixed-point numbers that have different scaling factors.

Start Lesson

Q-Numbers

Lesson 56: Power of 2 Scaling Factors

Learn how power-of-2 scaling factors work and why they enable efficient bitshift operations in fixed-point arithmetic.

Start Lesson

Lesson 57: Binary Representation of Power-of-2 Scaling Factors

Learn how power-of-2 numbers are represented in binary and why this makes bitshift operations efficient.

Start Lesson

Lesson 58: Smallest Value a Power-of-2 Fixed-Point Number Can Represent

Learn how to calculate the precision limits of power-of-2 fixed-point systems.

Start Lesson

Lesson 59: Largest Value a Power-of-2 Fixed-Point Number Can Represent

Learn how to calculate the maximum values that different uint types can store with power-of-2 scaling factors.

Start Lesson

Lesson 60: Largest Integer a Power-of-2 Fixed-Point Number Can Represent

Learn how to determine the maximum whole number values in power-of-2 fixed-point systems using bitwise interpretation.

Start Lesson

Lesson 61: Q-Number Notation

Learn the standard UQm.n notation for power-of-2 fixed-point numbers and how to convert between formats.

Start Lesson