Menu
Coddy logo textTech

Signed Integers

Part of the Fundamentals section of Coddy's Solidity journey. Lesson 7 of 53.

Use int256 when a whole number may be negative. A temperature change or a score adjustment can have a sign. A minus sign before a value makes a negative literal. Signed and unsigned types have different ranges, so keep the declared type consistent with the data.

The statements in this excerpt run inside the provided main function.

int256 change = -8;
console.log(change);

The signed variable keeps the negative value. int256 ranges from -2^255 through 2^255 - 1. A supplied signed argument can be positive, negative or zero. This is different from a uint256, whose range starts at zero.

Use a signed integer type when negative whole-number values are meaningful.

challenge icon

Challenge

Easy

Copy the signed adjustment to a local delta, then print it.

The tests pass arguments to main in this order: int256 adjustment. Each test starts with fresh contract state.

Use console.log for the requested output. Print only the requested values, one per line, with no extra labels unless the task specifies them.

Try it yourself

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "forge-std/console.sol";
contract Main {
    function main(int256 adjustment) external view {
        // Write your solution here.
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Solidity playground