0

I was trying to figure out the overflow in solidity, and I noticed that when I subtract one to a uint which was assigned by zero.

The value will become 115792089237316195423570985008687907853269984665640564039457584007913129639935

What does this monster mean?

For example

contract test{
    uint public a = 1;

    function subone(){
        a--;   
    }
}

After I execute twice subone, the value of a becomes that long number. The same thing happened when I have an array and I subtract its length to less than zero.

For example

pragma solidity ^0.4.17; 

contract X{
    uint256[] public array = [1];

    function X(){}

    function popLength() public{
        array.length--;
    }

    function getLength() constant returns(uint256){
        return array.length;
    }
}
0

That number is 2**256-1. In hexadecimal, it's 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.