Next: Functions
Up: Using MathMaps
Previous: Relational Operators
Bitwise operators are often useful when operating on raw data
(e.g. from instruments), so they are provided for use in MathMap
expressions. In this case, however, the values on which they operate
are floating-point values rather than the more usual pure integers. In
order to produce results which match the pure integer case, the
operands are regarded as fixed point binary numbers (i.e. with the
binary equivalent of a decimal point) with negative numbers
represented using twos-complement notation. For integer values, the
resulting bit pattern corresponds to that of the equivalent signed
integer (digits to the right of the point being zero). Operations on
the bits representing the fractional part are also possible, however.
The following bitwise operators are available:
- X1
X2: Rightward bit shift. The integer value of X2 is taken
(rounding towards zero) and the bits representing X1 are then
shifted this number of places to the right (or to the left if the
number of places is negative). This is equivalent to dividing X1 by
the corresponding power of 2.
- X1
X2: Leftward bit shift. The integer value of X2 is taken
(rounding towards zero), and the bits representing X1 are then
shifted this number of places to the left (or to the right if the
number of places is negative). This is equivalent to multiplying X1
by the corresponding power of 2.
- X1 & X2: Bitwise AND between the bits of X1 and those of X2
(equivalent to a logical AND applied at each bit position in turn).
- X1
X2: Bitwise OR between the bits of X1 and those of X2
(equivalent to a logical OR applied at each bit position in turn).
- X1
X2: Bitwise exclusive OR (XOR) between the bits of X1 and
those of X2 (equivalent to a logical XOR applied at each bit
position in turn).
Note that no bit inversion operator is provided. This is
because inverting the bits of a twos-complement fixed point binary
number is equivalent to simply negating it. This differs from the
pure integer case because bits to the right of the binary point are
also inverted. To invert only those bits to the left of the binary
point, use a bitwise exclusive OR with the value -1 (i.e. X
-1).
Next: Functions
Up: Using MathMaps
Previous: Relational Operators
KAPPA --- Kernel Application Package
Starlink User Note 95
Malcolm J. Currie & David S. Berry
2013 February 14
E-mail:starlink@jiscmail.ac.uk
Copyright © 2013 Science and Technology Facilities Council