Articles → BLOCKCHAIN → Integer Rollover In Solidity
Integer Rollover In Solidity
How Does Integer Rollover Happen?
Unchecked Keyword In Solidity
Example
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
contract ExampleIntegerRollOver {
uint8 public myUint8Decrement = 0;
uint8 public myUint8Increment = 255;
function decrementUintUnchecked() public {
unchecked {
myUint8Decrement--;
}
}
function decrementUint() public {
myUint8Increment++;
}
function incrementUintUnchecked() public {
unchecked {
myUint8Increment++;
}
}
function incrementUint() public {
myUint8Decrement--;
}
}
Decrementuintunchecked Function
Decrementuint Function
Incrementuintunchecked Function
Incrementuint Function