![]() |
![]() |
![]() |
![]() |
(..Operators..) | Contents | Index | (..Operators..) |
Furthermore there also exist binary operators in SCARLET, which process
integer expressions
thus elements of
.
Therefore they strictly make use of the value's internal binary
representation as a 32-bit number.
(For further explanation it will be useful to think of these binary
numbers as written down in a scheme with 32 fields, in which the
one at the left end
is used for the sign (+ corresponds to 0, - to 1) and the
remaining 31 bits to show the number itself.)
We distinguish between shift and logical operators
ShiftOp: | ||
<< | Shift to the left | |
>> | Shift to right |
BitOp: | ||
& | bitwise AND | |
| | bitwise inclusive OR |
The shift operators in SCARLET work like the corresponding
operators in C for signed variables.
means that the bit pattern of IntExpression1 is
IntExpression2 positions shifted to the left. In fact all bits
"dropping out" of the left side of the scheme are lost, while the scheme
is filled up with zeros behind the shifted number.
IntExpression2
must always be positive and less than the width of
IntExpression1 regarded as a binary number.
For the shift to the right the situation is very similar:
IntExpression1 is shifted
IntExpression2 positions to the
right, but here the sign of IntExpression1
decides which bit is used for the fill-up: 0 if the sign is positive and 1 if it is
negative.
11 << 4176 (00 ... 0000001011)
(00 ... 0010110000) -14 >> 1
-1.073.741.830 (1000 ... 001101)
(1100 ... 000110)
Looking at the binary operators & and |,
the binary representation is interpreted as a sequence of
logical values; every 1 is taken as TRUE, every 0 as
FALSE, so both expressions are bitwise combined with the logical
AND or OR
respectively, and the results of all single comparisons are returned as
0 or 1 again.
13 & -75 00 ... 01101 & 10 ... 00111 --------------- 00 ... 00101
The results of all binary operations are again integer expressions.
![]() |
![]() |
![]() |
![]() |
(..Operators..) | Contents | Index | (..Operators..) |