integersolidityuintuint32uint16

what is signed/unsigned integer in Solidity?


I found the following definition about signed/unsigned integers on a Solidity book from Packt:

Understanding integers
Integers help in storing numbers in contracts. Solidity provides the following two types of integer:

• Signed integers: Signed integers can hold both negative and positive values.
• Unsigned integers: Unsigned integers can hold positive values along with zero. They can also hold negative values apart from positive and zero.

I can understand that signed integers can hold both negative and positive values. Unsigned integers can hold positive values along with zero. In the definition it says that they can also hold negative values apart from positive and zero.

What this means? Can unsigned integer hold negative values or not? It's a mistake in the book or I don't get it?


Solution

  • [Unsigned integers] ... can also hold negative values apart from positive and zero.

    ^^ This part is incorrect.

    Unsigned means that the number doesn't have a + or - sign. So it can hold only 0 and positive values.