当前位置:网站首页>[2. Basics of Delphi grammar] 4 Object Pascal operators and expressions
[2. Basics of Delphi grammar] 4 Object Pascal operators and expressions
2022-07-01 17:39:00 【Janeb1018】
4.Object Pascal Operators and expressions
Operation is the processing and processing of data , Operators are symbols that operate on values of various data types in code .
stay Object Pascal in , Operators are divided into : Monocular operator and binocular operator .
An expression is an operation formula that represents an evaluation rule , Constants are separated by operators and parentheses 、 Variable 、 function 、 Object and other operands .
4.1 Arithmetic operators and arithmetic expressions
1. Arithmetic operator
Object Pascal The arithmetic operator in :
Operator | name | Example | Operator | name | Example |
---|---|---|---|---|---|
+ | Correct | +a | Div | Divide the whole number by | a Div b |
- | Take the negative | -b | Mod | Seeking remainder | a Mod b |
* | ride | a*b | + | Add | a+b |
/ | except | a/b | - | reduce | a-b |
The operation result is automatically converted to high precision ;
Division operations / Whether integer or real , The results are all real ;
Div and Mod The operand of must be an integer , The result is an integer ;
2. The precedence of arithmetic operators
Operator | priority |
---|---|
+ Correct 、- Take the negative | 1 |
*、/ | 2 |
Div、Mod | 3 |
+、- | 4 |
The same level operation is performed from left to right , Right parenthesis in expression , Calculate the expression in parentheses first , If there are multiple brackets , First calculate the expression in the inner bracket .
3. Arithmetic expressions
accord with Object Pascal The specified arithmetic expression should consider three aspects : grammar 、 priority 、 type . Let's give an example of :
for example :
The mathematical formula | Arithmetic expressions |
---|---|
x/(yz) | x/(y*z) |
(2x-y)/x | (2.0*x-y)/x |
lg4.5+0.3ln4.5 | log10(4.5)+0.3*ln(4.5) |
(5x^2.3+3)/(3/5) | (5*Power(x, 2.3)+3.0)/(3.0/5.0) |
4.2 Logical operators and Boolean expressions
4.2.1 Logical operators
Logical operators include : Boolean operator 、 Bitwise operators and relational operators .
1. Boolean operator
Boolean operators can only operate on Boolean operands , The result is Boolean . Basic Boolean operators :
NOT “ Not ” Operator
Calculate the opposite number of operands , Monocular operator .
x NOT x True False False True AND “ And ” Operator
Only if both operands are True when , The result of the operation is True.
x y x AND y False False False False True False True True True True Flase False OR “ or ” Operator
As long as one of the two operands is True, The result of the calculation is True.
x y x OR y False False False False True True True True True True False True XOR “ Exclusive or ” Operator
When two operands are different, the result is True
x y x XOR y Flase False False False True True True True False True False True
2. An operator
Bit operation is to perform operations on the binary bits of integer operands ,“ position ” Refers to binary bits , Bitwise operation means that adjacent operation results are not considered , Only the corresponding bits in the two operands are calculated .
An operator
The operator | give an example | Functional specifications |
---|---|---|
NOT | NOT x | take x Each binary bit of is negated , namely 1 Turn into 0,0 Turn into 1. |
AND | x AND y | And the corresponding bits of the two operands , A fellow 1 The result is 1 |
OR | x OR y | Or the corresponding bits of two operands , A fellow 0 The result is 0 |
XOR | x XOR y | XOR the corresponding bits of two operands , When the corresponding bit is different, it is 1 |
SHL | x SHL y | take x The binary bit of moves to the left y position , Move left 1 A bit is a ride 2 |
SHR | x SHR y | take x The binary bit of moves to the right y position , Move right 1 Bit is equivalent to dividing 2 |
Example :
x | y | operation | result |
---|---|---|---|
00100011 | NOT x | 11011100 | |
00100011 | 11101110 | x AND y | 00100010 |
00100011 | 11101110 | x OR y | 11101111 |
00100011 | 11101110 | x XOR y | 11001100 |
124=11111100 | 2 | x SHL y | 11111000 |
124=11111100 | 2 | x SHR y | 01111110 |
3. Relational operator
Relational operators are used to compare the values of two data of the same type , The result is Boolean .
Relational operator
Relational operator | operation | Operand type |
---|---|---|
= | be equal to | Simple type 、 character string 、 Variable type 、 class 、 Class reference 、 The pointer 、 Collection types |
<> | It's not equal to | Simple type 、 character string 、 Variable type 、 class 、 Class reference 、 The pointer 、 Collection types |
< | Less than | Simple type 、 character string 、 Variable type |
> | Greater than | Simple type 、 character string 、 Variable type |
<= | Less than or equal to | Simple type 、 character string 、 Variable type 、 Collection types |
>= | Greater than or equal to | Simple type 、 character string 、 Variable type 、 Collection types |
Relational operation of set type : hypothesis A and B It's two sets , be :
if A and B The elements of are exactly the same , be A=B by True, otherwise A<>B by True;
if A Any element of is also B The elements of , be A<=B by True, said A yes B Subset ;
if B Any element of is also A The elements of , be A>=B by True, said B yes A Subset ;
4.2.2 Boolean expression
Boolean expressions consist of Boolean operators and operands of boolean type . Boolean expressions can be used to describe complex judgment conditions .
for example : To describe whether a real number is in an interval [10,100] Inside , Then Boolean expression :
(x >= 10.0) and (x <= 100.0)
To describe whether a real number is in an interval [10,100] outside , Then Boolean expression :
(x < 10.0) or (x > 100.0)
4.3 String operators
Object Pascal String operator for :+, Used to connect two or more strings .
Format of string expression :
< String expressions > + {< character string >|< character >}
Example :
'Hello world' + '!' // The result is 'Hello world!' 'Delphi' + ' Programming ' // The result is 'Delphi Programming ' '12 3' + '4' + '5' + 'abc' + 'xyz' // The result is '12 345abcxyz'
4.4 Operator precedence
In addition to the above operators , And pointer operators 、 Set operators 、 Class operators and address taking operators ( We will learn these gradually in the following content ), All operators have priority ,Object Pascal The priority of the operator in the :
priority | Operator | describe |
---|---|---|
1 | @、NOT、+、- | Monocular operator |
2 | *、/、DIV、MOD、AND、SHL、SHR | Multiplication, division and some logical operators |
3 | +、-、OR、XOR | Add, subtract, and or operators |
4 | =、<>、<、>、<=、>=、in、is | Relationship 、 Set members and type comparison operators |
Some of the above operators are not learned so far , In the following chapters, we will gradually learn .
边栏推荐
- DNS
- 中国氮化硅陶瓷基板行业研究与投资前景报告(2022版)
- Alibaba cloud Li Feifei: China's cloud database has taken the lead in many mainstream technological innovations abroad
- SLO is increasingly used to achieve observability | Devops
- 智能运维实战:银行业务流程及单笔交易追踪
- Source code of new campus errand / campus task platform on mutual station
- 阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外
- Pytest learning notes (13) -allure of allure Description () and @allure title()
- PIP version problems: PIP problems still occur when installing akshare and using Tsinghua source and Douban source
- 【splishsplash】关于如何在GUI和json上接收/显示用户参数、MVC模式和GenParam
猜你喜欢
Cookies and session keeping technology
(1) CNN network structure
Official announcement! Hong Kong University of science and Technology (Guangzhou) approved!
[C supplement] [string] display the schedule of a month by date
【Try to Hack】vulnhub DC4
Euler function: find the number of numbers less than or equal to N and coprime with n
Vulnhub range hacker_ Kid-v1.0.1
Pytest learning notes (13) -allure of allure Description () and @allure title()
Iommu/smmuv3 code analysis (10) page table operation
[beauty detection artifact] come on, please show your unique skill (is this beauty worthy of the audience?)
随机推荐
Soft test software designer full truth simulation question (including answer analysis)
unity3d扩展工具栏
Integer array merge [JS]
GameFramework食用指南
深度优先遍历和广度优先遍历[通俗易懂]
In depth evaluation and development trend prediction report of China's ice cream market (2022 Edition)
Radhat builds intranet Yum source server
DNS
智能运维实战:银行业务流程及单笔交易追踪
(十七)DAC转换实验
China biodegradable plastics market forecast and investment strategy report (2022 Edition)
Intel's open source deep learning tool library openvino will increase cooperation with local software and hardware parties and continue to open
Unity3d extended toolbar
Openlayers 自定义气泡框以及定位到气泡框
[wrung Ba wrung Ba is 20] [essay] why should I learn this in college?
Kia recalls some K3 new energy with potential safety hazards
Kernel stray cat stray dog pet adoption platform H5 source code
vulnhub靶场-hacksudo - Thor
【C补充】【字符串】按日期排序显示一个月的日程
JDBC: deep understanding of Preparedstatement and statement[easy to understand]