Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the types of Solidity

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what are the types of Solidity". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Types

Solidity is a statically typed language, meaning that each variable (local or state variable) needs to specify the type of variable at compile time (or at least the type can be extrapolated). Solidity provides some basic types that can be used to combine into complex types.

There are two types of Solidity:

Value type (Value Type)-the variable always makes a copy of the value when assigning or passing parameters.

Reference type (Reference Types)

Value type (Value Type)

Value types include:

Boolean type (Booleans)

Integer (Integers)

Fixed length floating point (Fixed Point Numbers)

Fixed length byte array (Fixed-size byte arrays)

Rational numbers and integer constants (Rational and Integer Literals)

String constant (String literals)

Hexadecimal constant (Hexadecimal literals)

Enumeration (Enums)

Function type (Function Types)

Address type (Address)

Address constant (Address Literals)

Function type and address type (Address) have separate blog posts, please click to view.

Boolean type (Booleans)

Bool: the possible values are the constant values true and false.

Operators supported by Boolean types are:

! Logic is not

& & Logic and

| | Logic or

= = equal to

! = not equal to

Note: the operators * * & & and | * * are short-circuit operators, such as f (x) | | g (y). When f (x) is true, g (y) will not continue.

Integer (Integers)

Int/uint: represents signed and unsigned different digit integers. The keywords uint8 to uint256 (in 8 steps) are supported, and uint and int correspond to uint256 and int256 by default.

Supported operators:

Comparison operator: =, > (returns Boolean value: true or false)

Bit operator: &, |, ^ (XOR), ~ (bit reversed)

Arithmetic operators: +, -, unary operation, unary operation +, *, /,% (take remainder), * (power), > (right shift)

Description:

Integer division is always truncated, but if the operator is literal (literal later), it is not truncated.

Dividing an integer by 0 throws an exception.

The result of the shift operation depends on the number to the left of the operator. X > y and x / 2 are equal.

Negative shift cannot be performed, that is, the number to the right of the operator cannot be negative, otherwise a runtime exception will be thrown.

Note: in Solidity, the right shift is equivalent to division, so if you shift a negative number to the right, it will be 0 when rounding down, unlike infinite negative decimals in other languages.

Fixed length floating point (Fixed Point Numbers)

Note: fixed-length floating-point Solidity (when writing) is not fully supported, it can be used to declare variables, but not to assign values.

Fixed/ufixed: represents signed and unsigned fixed floating point numbers. The keywords are ufixedMxN and ufixedMxN. M represents the number of bits to be occupied by this type, which can range from 8 to 256 bits in 8 steps. N represents the number of decimal points, which can be between 0 and 80

Supported operators:

Comparison operator: =, > (returns Boolean value: true or false)

Arithmetic operators: +, -, unary operation, unary operation +, *, /,% (take remainder) Note: unlike float and double in most languages, M represents the fixed number of digits occupied by the whole number, including the integer part and the decimal part. So when a floating-point number is represented by a decimal number (M is smaller), the decimal part takes up almost the entire space.

Fixed length byte array (Fixed-size byte arrays)

Keywords are: bytes1, bytes2, bytes3,..., bytes32. (increments by step 1) byte stands for bytes1.

Supported operators:

Comparator: (returns bool)

Bit operator: &, |, ^ (XOR by bit), ~ (inverted by bit), > (shift right)

Index (subscript) access: if x is bytesI, when 0

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report