delphi 运算符

运算符是程序代码中对各个数据类型的运算符号:

1.赋值运算符 如: str := 'guilin';

2.比较运算符,在所有语言中,比较运算符都是基本相同的用法:

=,>,<,,>=,=<,<>;

3.逻辑表达式:

逻辑与: and

逻辑或: or

逻辑非:not

4.算数运算符:

+,-,*,/(浮点数);

整数除 div ;和/都是除,但2者的类型不一样;

取模 mod; 如:

var

   j : integer;

j := 105 mod 5; //j=5

5,按位运算符:

按位运算符能修改一个变量的单独各位,最常用的按位运算符可以把一个数左移或右移;或对两个数按位执行与,取反,或和异或运算;

unit d0007;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

const
w1 : word = 60038;//二进制数为:11101010 100000110
w2 : word = 5497; //二进制数为 00010101 01111001
var
w : Word;
{取反 not,只有一个运算符}
procedure TForm1.Button1Click(Sender: TObject);
begin

w := not w1;
{
w1 11101010 100000110
w 00010101 011111001
}
ShowMessage(inttostr(w));
w := not w2;
ShowMessage(IntToStr(w));
end;

end.

6.加减运算过程:

inc()  //加;

dec() //减;

如:

var 

  i  : integer;

i :=100;

dec(i); // i = 99;

 

posted @ 2012-10-19 12:47  delphiclub  阅读(510)  评论(0编辑  收藏  举报