122-32000 Parallax Inc, 122-32000 Datasheet - Page 262

MANUAL PROPELLER

122-32000

Manufacturer Part Number
122-32000
Description
MANUAL PROPELLER
Manufacturer
Parallax Inc
Datasheets

Specifications of 122-32000

Accessory Type
Manual
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
For Use With/related Products
Propeller Education (PE) Kit
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
Operators – Spin Language Reference
X := ||Y
If
is -15, the absolute value, 15, would be stored into
.
Y
X
Absolute Value becomes an assignment operator when it is the sole operator to the left of a
variable on a line by itself. For example:
||Y
This would store the absolute value of
back into
.
Y
Y
Sign-Extend 7 or Post-Clear ‘
~
This operator is a special, immediate operator that has a dual purpose depending on which
side of the variable it appears on. It can only be used in run-time variable expressions. The
Sign-Extend 7 form of the operator appears to the left of a variable and the Post-Clear form
appears to the right of a variable.
The following is an example of the Sign-Extend 7 operator form:
Y := ~X + 25
The Sign-Extend 7 operator in this example extends the sign of the value,
in this case, from
X
bit 7 up to bit 31. A 32-bit signed integer is stored in twos-complement form and the most
significant bit (31) indicates the sign of the value (positive or negative). There may be times
where calculations on simple data result in byte-sized values that should be treated as a
signed integer in the range of -128 to +127. When you need to perform further calculations
with those byte-sized values, use the Sign-Extend 7 operator to convert the number into the
proper 32-bit signed integer form. In the above example, assume
represents the value -20,
X
which in 8-bit twos-complement form is actually the value 236 (%11101100). The
portion
~X
of the expression extends the sign bit from bit 7 all the way up to bit 31, converting the
number to the proper 32-bit twos-complement form of -20 (%11111111 11111111 11111111
11101100). Adding that sign-extended value to 25 results in 5, the intended result, whereas it
would have resulted in 261 without the proper sign extension.
The following is an example of the Post-Clear operator form.
Y := X~ + 2
The Post-Clear operator in this example clears the variable to 0 (all bits low) after providing
its current value for the next operation. In this example if
started out as 5,
would provide
X
X~
the current value for the expression (5 + 2) to be evaluated later, then would store 0 in
. The
X
Page 262 · Propeller Manual v1.0

Related parts for 122-32000