Solidity gives the usage of literal for assignments to variables. Literals have names; the values themselves. Variables can change their values during program execution, but a literal remains value throughout. Take at various literals:
- Ilustrations of integer literals are 1, 10, 1,000, -1, and -100.
- Examples of string literals are “Ritesh” and ‘Modi’. String literals in single or .
- Examples of address literals are 0xca35b7d915458ef540ade6068dfe2f44e8fa733c and 0x1111111111111111111111111111111111111111.
- Hexadecimal literals are prefixed with the hex keyword. An example of hexadecimal literals is hex”1A2B3F”.
- Solidity supports decimal literals with of dots. Examples include 4.5 and 0.2.
Integers help in storing numbers in contracts. Solidity provides two integer:
- Signed integers: Signed integers may hold both negative and positive values.
- Unsigned integers: Unsigned integers can hold only positive values zero. also hold negative values positive values.
There are multiple flavors of literals and integers in solidity types. Solidity gives uint8 type to represent 8-bit unsigned integer and thereon in multiples of 8 till it reaches 256. In short, there can32 different declarations of unit with different multiples of 8, uint8, uint16, unit24, as far as uint256 bit.
Mathematical operations addition, subtraction, multiplication, division, exponential, negation, post-increment, and pre-increment performed on integers. screenshot shows these examples:
Similarly, there are equivalent data types for integers int8, int16 till int256. requirements, an appropriately sized integer should be chosen. , while storing values between 0 and 255 uint8 , and while storing values between -128 to 127 int8 is more suitable. For higher values, larger integers used. The default value for both signed and unsigned integers is zero, to which initialized automatically at the time of declaration. Integers are value types; however, when used as an array as reference types.
- Solidity value types include Booleans, integers, fixed point numbers, addresses, contract types, fixed-size byte arrays, rational and integer literals, and enums.
- Reference types such as arrays and structs can be stored in these options: memory , storage and calldata .