|
  
Bitwise Operators
Six operators process numeric data as though each number is a
collection of ones and zeros. For example, a Bitwise And of the number 5 and 6
(5&6) produces the result 4.
The number 5 in binary form is 101. Similarly, the number 6 is
110. If you And together each pair of corresponding digits
in the two binary numbers you get 100, which is the binary
representation for the number 4. That is,
101 5
& 110 6
100 4
Although DScript uses floating-point notation to represent all
numbers, when you perform a bitwise operation the operands are
first converted to 32-bit integers.
Each bitwise operator is described below.
Bitwise And x&y
Each digit in the result is a 1 if both corresponding digits
in x and y
are 1.
Bitwise Or x|y
Each digit in the result is a 1 if either corresponding digit
in x or y
is 1.
Bitwise Exclusive Or x~y
Each digit in the result is a 1 if the corresponding digits in
x and y
are different.
Bitwise Not ~x
Inverts all bits in x. That
is, Bitwise Not changes all zeros in x to ones and all ones to zero.
Left Shift x<<y
Moves all digits in x left by y digits. Bits shifted off the left end
are lost.
Right Shift x>>y
Moves all digits in x right by
y digits. Bits shifted off the
right end are lost. If x is
positive, zeros are shifted in on the left. If x is negative, ones are shifted in.
Zero-Fill Right Shift x>>>y
Same as Right Shift except
that zeros are shifted in on the left regardless of the sign of x.
|