Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational and Logical Operators Selim Aksoy Bilkent University Department of Computer Engineering

Similar presentations


Presentation on theme: "Relational and Logical Operators Selim Aksoy Bilkent University Department of Computer Engineering"— Presentation transcript:

1 Relational and Logical Operators Selim Aksoy Bilkent University Department of Computer Engineering saksoy@cs.bilkent.edu.tr

2 Summer 2004CS 1112 Relational Operators Relational operators are used to represent conditions (such as “space  0” in the water tank example) Result of the condition is either true or false In MATLAB: false is represented by 0 true is represented by 1 (non-zero)

3 Summer 2004CS 1113 Relational Operators OperationResult 3 < 41 3 <= 41 3 == 40 3 ~= 41 3 > 40 4 >= 41 ‘A’ < ‘B’1

4 Summer 2004CS 1114 Relational Operators Don’t confuse equivalance (==) with assignment (=) Be careful about roundoff errors during numeric comparisons (you can represent “x == y” as “abs(x-y) < eps”) Relational operations have lower priority than arithmetic operations (use parentheses to be safe, though)

5 Summer 2004CS 1115 Logical Operators More complex conditions can be represented by combining relational operations using logic operators Logical operators: &AND |OR xorExclusive OR ~NOT

6 Summer 2004CS 1116 Logical Operators inputandorxornot aba & ba | bxor(a,b)~a 000001 010111 100110 111100

7 Summer 2004CS 1117 Operator Hierarchy Processing order of operations: parenthesis (starting from the innermost) exponentials (left to right) multiplications and divisions (left to right) additions and subtractions (left to right) relational operators (left to right) ~ operators & operators (left to right) | operators (left to right)


Download ppt "Relational and Logical Operators Selim Aksoy Bilkent University Department of Computer Engineering"

Similar presentations


Ads by Google