I need to understand a couple of things:
- What is the maximum value an int and uint can store?
- Are the maximum values stored in int and uint the same?
uint
is short for uint256
, so it can store 2^256 values - because it's unsigned the maximum value is 2^256-1 (zero needs one space). What is the maximum input value for function uint256 parameter?int
is short for int256
and it can store the same amount of values - because it's signed the maximum (positive) value is 2^256 / 2 - 1.So the maximum values of uint
and int
are not the same. They have the same amount of values but int
needs to store values also for negative numbers.
You can find more details at: Max/min values of standard data types
It works as same as other programming languages.
uint
can store 2^256-1
numbers.
int
store half of it. e.g. 2^256/2-1
numbers.
Int8 — [-128 : 127]
Int16 — [-32768 : 32767]
Int32 — [-2147483648 : 2147483647]
Int64 — [-9223372036854775808 : 9223372036854775807]
Int128 — [-170141183460469231731687303715884105728 : 170141183460469231731687303715884105727]
Int256 — [-57896044618658097711785492504343953926634992332820282019728792003956564819968 : 57896044618658097711785492504343953926634992332820282019728792003956564819967]
UInt8 — [0 : 255]
UInt16 — [0 : 65535]
UInt32 — [0 : 4294967295]
UInt64 — [0 : 18446744073709551615]
UInt128 — [0 : 340282366920938463463374607431768211455]
UInt256 — [0 : 115792089237316195423570985008687907853269984665640564039457584007913129639935]
Don’t trust verify
Here is how much uint8 can store in decimals: 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 or 2^256
2^7 * 1 + 2^6 * 1 + 2^5 * 1 + 2^4 * 1 + 2^3 * 1 + 2^2 * 1 + 2^1 * 1 + 2^0 * 1
= 2^8 - 1
= 255
By the same token, uint256 can store in decimals:
2^256 - 1
= 115792089237316195423570985008687907853269984665640564039457584007913129639935
Scientific notation of the max value of uint256, since it is sometimes easier to reason with:
Raw Value
115792089237316195423570985008687907853269984665640564039457584007913129639935
Scientific Notation:
1.15792089237320006134268624010 × 10^77
Or
1.15792089237320006134268624010e+77