XML

kent logo

CO631 Anonymous Questions and Answers Keyword Index

This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.

To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.

Keyword reference for operators

2004

Question 102 (2004):

Is it possible to specify more than one condition in an "IF" process ? For example:

    IF
      x = 0 AND y = 0
        -- do something

If so which operators should be used ? When I compile something similar to the above I get an error saying:

    Expected new line, found AND

Answer 102:

This error occurs because you need explicit bracketing (occam has no operator precedence), even though the alternatives don't make much sense in this case. The correct way to write that would be:

    IF
      (x = 0) AND (y = 0)
        -- do something

Keywords: q7 , operators

2002

Question 25 (2002):

What does each of this mean?

  /\, \/, ><, >> and <<

Answer 25:

These are described in slide 4-35 and section 1.2 of the Checklist paper. From there, you can infer that they are infix binary operators between INTs and that they return INTs. However, those pages does not say what those operations were! For that, you need to have attended the lecture when they were presented.

They are (mostly bitwise) logical operations:

  /\  - bitwise anding (between the two operands)
  \/  - bitwise oring (between the two operands)
  ><  - bitwise exclusive-oring (between the two operands)

  >>  - logical shift right (by right-operand number of bits)
  <<  - logical shift left (by right-operand number of bits)

The logical shifts are the same as in Java. They are not circular shifts - zeroes are pulled in to fill empty bits.

There is also the prefix unary operator:

  ~   - flip all the bits in the operand

These operators enable low-level (i.e. efficient) bit-twiddling to be done. This is needed to access specific bit fields common, for example, to memory mapped registers.

Note: these operators are overloaded so that they can be used on INT16s, INT32s, INT64s and BYTEs, as well as on INTs. The two operands must be exactly the same type - and the result of the operation is that same type. The bitwise operators are associative - for example, we may write:

  a /\ b /\ c

without any brackets. This contrasts with the + operation, which require brackets for a three-way add since, of course, with fixed precision numbers:

  a + (b + c)   is not equal to   (a + b) + c

and so we have to put in brackets to say what we want!

Keywords: operators

Valid CSS!

Valid XHTML 1.0!

Last modified Mon May 15 17:39:46 2006
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.