Sunday, June 12, 2011

2.4 Operators

2.4 Operators
To manipulating and data process borland provides a variety operators, every operator has a level of hierarchy that is the order of implementation if the operator involved in a process, ex : if there is expression A+B*C, then will be the first will be process is B*C after that the result of B*C will be addition with A. this is due to the multiplication operator(*) hierarchy higher than the increment operator(+). if on the process there is same operators then the left character will be the first process.
Operator Hirarchy
@,not Highest
*, /, div, mod,and,shl,shr,as second
+, -,or,xor Third
=, <>, <,>, <=, >=,in,is Forth
2.4.1 Assignment Operators
Assignment operators symbolized with :=, it is function to insert data to a variable. it is writing:
<variable>:= < expression>;
examples:

bilangan := 0;
harga := 500;
banyak := 5;
jumlah := banyak*harga;
n:=n+1;
2.4.2 Arithmetic Operators
Arithmetic operators used to arithmetic process.Delphi have several Arithmetic operators:
operator process process type result type
* multiplication Integer Integer
Real Real
/ Division Integer Real
Real Real
Div Division round Integer
Integer
Mod Residual division Integer
Integer
+ Addition Integer Integer
Real Real
- Subtraction Integer Integer
Real Real
operators below it usually called binary arithmetic operators
such as examples, view the snipped program like this :

A := 1 * 2 ; // the result is 2
A := 4 / 2 ; //the result is 2
A := 5 div 2; //the result is 2, rounded down
A := 5 mod 2 ; //the result is 1, rounded up
A := 1 + 2 ; //the result is 2
A := 4 - 2 ; //the result is 2
how with he exponent operators. delphi has no exponent operators,
and it changing with use mathemaical formulas : ax exp(x * ln(a)). note the following program snippet:

A := 2;
B := 3;
C := exp (B*ln(A); // C= 9
D := exp (B*ln(5); //D=125

2.4.1 Relation Operators
Relation operators used to compare a data (expression) with the other data( expression) and generates the logic value (boolean) TRUE or False. of course to comparing 2 data, they must have similar type.
Operators Description
= equals to
<> not equals to
< less than
> greater than
<= less than or equals to
>= greater than or equals to
some examples in use compare operator :

A := 2 > 3; //false
A := 2 + 2 > 3; //true
A := 3 > 2 + 2; //false
A := 3 >= 3; //true
2.4.1 Logic Operators
logic operators used to expressing 1 or more data ( expression) logic (boolean). and generates new logic data (boolean). table logic operators
operators
Not No
And and
Or or
Xor Exclusive or
logic operator Not have a result the opposite data value of logic and have a high level in hierarchy operator logic.
view a table of logic operator Not
Expression Value
Not True False
Not False True
table of Operator And
Expression Value
False And False False
False And True False
True And False False
True And True True
table of Operator Xor
Expression Value
False And False False
False And True True
True And False True
True And True False

No comments:

Post a Comment