What is Signed Integer?

Signed integers represent positive and negative whole numbers. Signed integers are int in Solidity. In two’s complement notation, a signed integer’s MSB denotes its sign. Zero MSB is positive. MSB 1 is negative. The number magnitude is the leftover bits. 

  • int8 may represent integers from -128 to 127, with 0 in the MSB signifying positive numbers and 1 negative number. 
  • Solidity’s default 256-bit int types may represent integers from -2^255 to 2^255-1. 
  • Solidity has fixed-size int types of 8, 16, 32, 64, 128, and 256 bits.

Solidity supports arithmetic, logical, and bitwise operations with signed integers. Signed integers represent balances, prices, and other positive or negative quantities in smart contracts. Signed integers may overflow and underflow, which can affect smart contracts. Int variables wrap around to their minimum values if increased past their maximum values. Handling signed integers carefully helps prevent smart contract problems and vulnerabilities.

Signed integers in Solidity represent positive and negative whole numbers. In two’s complement notation, the MSB represents the sign while the remaining bits denote the magnitude. Solidity’s int types may represent numbers from -2^255 to 2^255-1 and have a default size of 256 bits. Avoid overflow and underflow when using signed integers in smart contracts’ arithmetic, logical, and bitwise operations.

Solidity – Integers

Integers help store numbers in smart contracts. Solidity provides two types of integers:

  • Signed Integers: Signed integers can hold both positive and negative values, ranging from -2 ^ 255 to 2 ^255 – 1.
  • Unsigned Integers: Unsigned integers can hold only integer values equal to or greater than zero, ranging from 0 to 2 ^256 – 1.

Similar Reads

What is Signed Integer?

Signed integers represent positive and negative whole numbers. Signed integers are int in Solidity. In two’s complement notation, a signed integer’s MSB denotes its sign. Zero MSB is positive. MSB 1 is negative. The number magnitude is the leftover bits....

What is an Unsigned Integer?

Positive integers are unsigned. Solidity uses uint for unsigned numbers. Unsigned integers do not utilize the MSB to identify signs. Unsigned integers indicate the number magnitude with all bits....

Signed integer vs Unsigned integer

Below are the differences between signed integers and unsigned integers:...

uint vs uint256

Below are the differences between uint and uint256:...