The Logic Operator, NOT

Authors

Publication

Date

Pages

BASIC Terms

For many of us, computer logic is a bit difficult to understand, and articles like the one reputed to be by Sharon Z. Aker in the July ’88 issue of UPDATE muddies the water more. On page 14, under the title of Priorty, the article states that NOT B<C is interpreted as (NOT B)>C. This is wrong. NOT applies to the entire expression B<C as the < operator has a higher priority than NOT and the computer will evaluate B<C first. Look at page 228 of the manual for a priority listing.

NOT applied to a condition can result only in a logic value of 0 or 1, regardless of the appearance of the condition. For example, consider…..

NOT X = 50

This is interpreted by the computer as….

NOT (X = 50)

If X does equal 50, the condition, X = 50, is TRUE and results in a logic value of 1 for this condition. Then NOT 1 has a logic value of 0.

Conversely, if X has a value of anything other than 50, the condition is considered FALSE, and X = 50 results in a logic value of 0. Then NOT 0, in turn, has a logic value of 1, and the THEN action will take place.

We can show this by a short test program…….

10 LET X = 50
20 IF NOT X = 50 THEN PRINT "Yes"
30 IF NOT (X = 50) THEN PRINT "OK"
40 PRINT "End of test"

Now change the value of X in line 10 to anything but 50 and lines 20 and 30 will print out their strings. Why? Because X = 50 is not TRUE and its logic value becomes 0. Now, NOT 0 gives a logic value of 1. As the entire expression has a logic value of 1, the THEN action takes place.

The parentheses in line 30 are not necessary, but if you wish to make the evaluation of an expression clear, use them. The computer simply ignores superfluous parentheses, and evaluates X = 50 first because of the priority of the = operator.

Let’s go a step further. The computer considers all logic on a numerical basis. To the computer, every logic term that is TRUE is assigned the number 1; otherwise it gets a 0. We can put this to a test by adding lines such as the following to our test program…..

15 PRINT X = 50
25 PRINT NOT X = 50
35 PRINT NOT (X = 50)

and we will get nothing but the numbers 1 and/or 0, on printout of these lines.

You can get the same response by evaluating a logic statement yourself and substituting the resulting logical value in the computer line. Instead of line 20 as written above, write it as…….

20 IF 1 THEN PRINT "Yes"

and the computer will print the string. Change the 1 to 0 and the computer will not print the string. As we said before, the computer recognizes every thing but 0 as the number 1. So now use something like -3 in place of the 1. Again, the line will print out the string word.

If you get this concept of logic well established in your mind, you will have little or no trouble with logic NOT from here on in.

There is yet another way of treating logic NOT. You can change any expression wherein it appears to an equivalent one by recalling that it merely reverses logic TRUE and FALSE. In doing so, NOT drops out of the expression. So NOT X = 50 can be replaced by X <> 50. Shall we try another? OK. NOT Y > 10 can be replaced by Y <= 10. I personally don’t prefer this way of handling NOT because we tend to forget how the computer itself treats this unique operator.

Products

 

Media

 

Image Gallery

Source Code

Scroll to Top