Bitwise functors

The operands and value of these evaluable functors are integers which are treated as a binary sequences of bits. The value is implementation defined when an operand or value is negative because the representation of a negative integer is implementation defined.

Templates and modes represent a specification for the type of the values when the arguments of the evaluable functor are evaluated as an expression, and the type of its value. A specific notation is employed for the structure and type of the arguments and value:

1. (>>)/2 (bitwise right shift)

'>>'(N, S) evaluates the expressions N and S with values VN and VS and has the value of VN right-shifted VS bit positions.

The value shall be implementation defined depending on whether the shift is logical (fill with zeros) or arithmetic (fill with a copy of the sign bit).

The value shall be implementation defined if VS is negative, or VS is larger than the bit size of an integer.

Templates and modes for the predicate are as follows:

'>>'(int-exp, int-exp) = integer

Note that >> is an infix predefined operator.

1.1 Example tests

First of all, let's start an appropriate fixture.

Evaluable value(String evaluable)
'>>'(16, 2). 4
'>>'(19, 2). 4
'>>'(-16, 2). -4

2. (<<)/1 (bitwise left shift)

'<<'(N, S) evaluates the expressions N and S with values VN and VS and has the value of VN left-shifted VS bit positions, where the VS least significant bit positions of the result are zero.

The value shall be implementation defined if VS is negative, or VS is larger than the bit size of an integer.

Templates and modes for the predicate are as follows:

'<<'(int-exp, int-exp) = integer

Note that << is an infix predefined operator.

2.1 Example tests

First of all, let's start an appropriate fixture.

Evaluable value(String evaluable)
'<<'(16, 2). 64
'<<'(19, 2). 76
'<<'(-16, 2). -64

3. (/\)/2 (bitwise and)

'/\'(B1, B2) evaluates the expressions B1 and B2 with values VB1 and VB2 and has the value such that each bit is set iff each of the corresponding bits in VB1 and VB2 is set.

The value shall be implementation defined if VB1 or VB2 is negative.

Templates and modes for the predicate are as follows:

'/\'(int-exp, int-exp) = integer

Note that /\ is an infix predefined operator.

3.1 Example tests

First of all, let's start an appropriate fixture.

Evaluable value(String evaluable)
'/\'(10, 12). 8
'/\'(10, 12). 8
'/\'(17 * 256 + 125, 255). 125
'/\'(-10, 12). 4

4. (\/)/2 (bitwise or)

'\/'(B1, B2) evaluates the expressions B1 and B2 with values VB1 and VB2 and has the value such that each bit is set iff at least one of the corresponding bits in VB1 and VB2 is set.

The value shall be implementation defined if VB1 or VB2 is negative.

Templates and modes for the predicate are as follows:

'\/'(int-exp, int-exp) = integer

Note that \/ is an infix predefined operator.

4.1 Example tests

First of all, let's start an appropriate fixture.

Evaluable value(String evaluable)
'\/'(10, 12). 14
'\/'(10, 12). 14
'\/'(125, 255). 255
'\/'(-10, 12). -2

5. (\)/1 (bitwise complement)

'\'(B1) evaluates the expression B1 with value VB1 and has the value such that each bit is set iff the corresponding bit in VB1 is not set.

The value shall be implementation defined.

Templates and modes for the predicate are as follows:

'\'(int-exp, int-exp) = integer

Note that \ is an prefix predefined operator.

5.1 Example tests

First of all, let's start an appropriate fixture.

Evaluable value(String evaluable)
'\'('\'(10)). 10
\(\(10)). 10
\(10). -11