I know that a Uint is the same type of a Uint256 and both size is 256 bits, but how many number digits accept without launch an overflow in a smart contract ejecution?
Asked
Active
Viewed 1,207 times
1 Answers
4
I did this simple test over Remix IDE avoiding declaration errors. I think is not exactly and depends of the digit number and position, but maybe helps you.
//UINT digits
uint8 myUint8 = 123; //3
uint16 myUint16 = 12345; //5
uint32 myUint32 = 1234567890; //10
uint64 myUint64 = 12345678901234567890; //20
uint128 myUint128 = 123456789012345678901234567890123456789; //39
uint256 myUint256 = 12345678901234567890123456789012345678901234567890123456789012345678901234567; //77
Extrange planet
- 685
- 5
- 11
2^N - 1it has1 + trunc(N * log_10(2))decimal digits, so with N bits you can fully represent integers withtrunc(N * log_10(2))decimal digits. I think this formula matches your findings +/- 1. – Ismael Apr 01 '21 at 17:42