Jamaica Gleaner

Relational operators and truth tables

- NATALEE A. JOHNSON Contributo­r Natalee Johnson teaches at Ardenne High School. Send questions and comments to kerry-ann.hepburn@gleanerjm.com

GOOD DAY, students. This is lesson 24 in our series of lessons. In this week’s lesson, we will be looking at relational, arithmetic and logical operators as well as truth tables.

The relational operators are used for comparison of the value of one element with another. There are six types of relational operations: equal, greater than, less than, greater than or equal to, less than or equal to, and not equal to. Each of these operations can be used to compare the values of the variables. The result of each of these operators is either true or false. When using these operators, make sure all the arguments are the same data type. Integers should be compared with integers, strings with strings, and so on. Table 1 reviews each of these operators. Let us look at an example. Table 2 shows a truth table with examples for each of the relational operators. As the table shows, A is set to 60 and B is set to 30. When we check equally with the equal operator, both sides must be equal or same for the expression to be true. Because the 60 is not equal to 30, the A= B is false. In this case, the expression is true because 60 is greater than 30. Using similar logic, the table shows results for other relational operators.

BOOLEAN OPERATORS AND TRUTH TABLES

A truth table shows the output states for every possible combinatio­n of input states. The symbols ‘0’ (false) and ‘1’ (true) are usually used in truth tables. There are three main logical operators we will concentrat­e on for the CSEC level and they are: AND, OR and NOT. For every logical operator, we are going to be examining its correspond­ing truth table.

THE ‘AND’ OPERATOR

For the ‘AND’ operator, the output Q is true if input A AND input B is both true: Q= A AND B

TRUTH TABLE THE ‘OR’ OPERATOR

For the ‘OR’ operator, the output Q is true if input A OR input B is true (or both of them are true): Q= A OR B

TRUTH TABLE THE ‘NOT’ OPERATOR TRUTH TABLE

The output Q is true when the input A is NOT true, the output is the inverse of the input: Q = NOT A A NOT gate can only have one input.

THE ARITHMETIC OPERATORS

You are more accustomed to using these operators in your daily life. Please see table below:

You may not have come across the modulus operator before. It just calculates the remainder after dividing the value of the expression on the left of the operator by the value of the expression on the right. For this reason, it is sometimes referred to as the remainder operator.

Example 2 4 % 4 would produce 0, because 4 divided by 4 leaves a remainder of 0

We have come to the end of lesson 24. See you next week, when we will look at modularity/top down design to end this unit. Remember, if you fail to prepare, you prepare to fail.

 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??

Newspapers in English

Newspapers from Jamaica