Signed integer vs Unsigned integer
Below are the differences between signed integers and unsigned integers:
Parameters | Signed Integers | Unsigned Integers |
---|---|---|
Represents | Positive and negative whole numbers. | Non-negative whole numbers. |
Data Type | int | uint |
Default Size | 256 bits | 256 bits |
Size Range | 8-256 bits | 8-256 bits |
Positive Values Representation | The most significant bit (MSB) is 0 | All bits represent the magnitude |
Negative Values Representation | The most significant bit (MSB) is 1 | N/A |
Maximum Value | 2^(n-1)-1 | 2^n-1 |
Overflow and Underflow Issues | More prone to overflow and underflow issues due to negative values representation | Less prone to overflow and underflow issues |
Common Use Cases | Balances, prices, and other numbers that may be positive or negative | Quantities, amounts, and other values that are guaranteed to be non-negative |
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.
Contact Us