Original title: " A minimalist introduction to Solidity: 2. Numerical types "
Original source: 0xAA
I am re-learning solidity recently, to consolidate the details, and also write a "Solidity minimalist introduction" for beginners to use (programmers can find another tutorial), updated 1 week -3 speaking.
All codes are open source on github: github.com/AmazingAng/WTFSolidity
Solidity Variable type Value type (Value Type): Including Boolean type, integer type, etc., when this type of variable is assigned, the value is directly passed. Reference type (Reference Type): Including arrays and structures, such variables take up a lot of space, and the address is directly passed when assigning a value (similar to a pointer). Mapping Type: Hash table in Solidity. Function Type (Function Type): In the Solidity documentation, functions are classified as numeric types, but I think they are very different from other types, so they are classified into a separate category.
We only introduce some commonly used types, not commonly used ones. This article covers numeric types, Lecture 3 covers function types, and Lecture 4 covers references and mappings.
Boolean is a binary variable, the value is true or false.

Boolean Operators, including:
! (logical NOT)
&& (logical AND, "and")
||(logical or, "or")
==(equal)
!=(not equal)
< /p>
Code:

< /p>
In the above code: the value of the variable _bool is true; _bool1 is the negation of _bool, which is false; _bool && _bool1 is false; _bool || _bool1 is true; _bool == _bool1 is false; _bool != _bool1 is true.
Integer type is an integer in solidity, the most commonly used ones include

Commonly used Integer operators include:
Comparison operators (returning a Boolean value): <=, <, ==, !=, >=, >
Arithmetic operators: +, -, unary operation -, +, *, /, % (remainder), ** (power)
Code:

You can run the code to see what the 4 variables are. A POAP for a correct answer?
The address type (address) stores a 20-byte value (the size of an Ethereum address). Address types also have member variables and serve as the basis for all contracts. There are ordinary addresses and addresses where ETH can be transferred (payable). The payable address has two members, balance and tranfer(), which are convenient for querying ETH balance and transfer.
Code

When we introduce functions in the next lecture, we will introduce how to use the address type.
There are two types of byte array bytes, one One is of fixed length (byte, bytes8, bytes32), and the other is of variable length. The fixed length is a numeric type, and the variable length is a reference type (to be discussed later).
Fixed-length bytes can store some data and consume less gas.
Code:


It can be explicitly converted to and from uint, and will check whether the converted positive integer is within the length of the enumeration Inside, otherwise an error will be reported:

A relatively unpopular variable of enum, almost no one uses it.
In the second lecture, we introduced 4 variable types in solidity, and introduced in detail the Boolean type, integer type, address, and fixed length in the value type. Byte arrays and enumerations. We will introduce several other types later.
Original link blockquote>
Welcome to join the official BlockBeats community:
Telegram Subscription Group: https://t.me/theblockbeats
Telegram Discussion Group: https://t.me/BlockBeats_App
Official Twitter Account: https://twitter.com/BlockBeatsAsia