1. Arithmetic operators
The following are the arithmetic operators recognized by BASIC.
TABLE C2.1 Arithmetic Operators
Operators Operation Example
+ Addition 25+10
- Subtraction 25-10
* Multiplication 25*10
/ Division 25/10
^ Exponentiation 2^5
2. Relational operators
Relational Operators let you compare two values. The result of the comparison is either true or false. Relational operators are used to compare variables, or constants of the same type for example :
We can not compare numeric constant with string constant.
There are six relational operators in BASIC. They are mentioned in the table below :
Table C2.2 Relational Operators
Operator Relation Tested Expression
= Equality (equal to) x = y
<> Inequality (Not equal to) x<>y
< Less than x < y
> Greater than x > y
< = Less than or equal to x < = y
> = Greater than or equal to x > = y
3. Logical operators
Logical operators perform tests on multiple relations or Boolean operations.
The logical operator returns a result which is either true or false. There are three commonly used logical operators :
1. AND
2. OR
3. NOT
Note : Boolean Operation - An operation which functions in accordance with the rules of BOOLEAN ALGEBRA ( A type of mathematics which involves working with binary numbers.
1. AND operator
Table C 2.3 Truth Table for Results of AND operation
Value Value Result
X Y X AND Y
T T T
T F F
F T F
F F F
Table C 2.3 above shows the TRUTH Table for AND operation. As you can see from the table, when the value of both X and Y are TRUE (T) the result of AND operation between X and Y (i.e. X AND Y) is TRUE(T). If any one of the value is FALSE(F), the result is FALSE(F). If both the values are FALSE(F), the result is also FALSE(F).
Note : Truth Table - A mathematical table that states values and units of all possible combinations (Boolean relationship) of output values a function of input.
Note : Truth Table - A mathematical table that states values and units of all possible combinations (Boolean relationship) of output values a function of input.
2. OR operator
Table C 2.4 Truth Table for Results of OR operation
Value Value Result
X Y X OR Y
T T T
T F T
F T T
F F F
Table C 2.4 shows the Truth Table for OR Operation. As you see from the table, when the value of X and Y are True (T), the result of OR operation between X and Y (i.e. X OR Y) is True (T). If any one of the value is TRUE (T), the result is True (T). If both the values are False(F), then the result will be False(F).
3. NOT operator
Table C 2.5 Truth Table for the Result of NOT Operator
Value Result
X NOT X
T F
F T
Table C 2.5 shows the Truth Table fro NOT operator. NOT operation has to be performed on a single value. When the value of X is True(T), the result of NOT operation on X (i.e. NOT X) will be FALSE(F). When the value of X is FALSE(F), the result will be TRUE(T). Thus, the result of the NOT operation is the complementary of the given value.
4. String operators
The BASIC interpreter compares strings by taking one character at a time from each string. The ASCII code are used for the comparison purpose. If the ASCII codes in each strings are the same, the strings are equal.
To compare strings. the same relational operators as mentioned before (to compare numbers) can be used.
Table C 2.6 String operators
Operators Meaning Example
= Equal to X$ = Y$
< > Unequal X$ < > Y$
< Less than X$ < Y$
> Greater than X$ > Y$
< = Less than and equal to X$ < = Y$
> = Greater than and equal to X$ > = Y$
Example 1
"AA" < "AB"
"CLASS 9 = "CLASS 9"
Strings can be connected by using the plus (+) sign.
Example 2
if X$ = "BEAUTI" AND Y$= "FUL"
Both these strings can be combined as :
X$ + Y$ = > BEAUTIFUL
No comments:
Post a Comment