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

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
Shift Arithmetic Right ‘
’, ‘
~>
~>=
The Shift Arithmetic Right operator is just like the Shift Right operator except that it
maintains the sign, like a divide by 2, 4, 8, etc on a signed value. Shift Arithmetic Right can
be used in variable and integer constant expressions, but not in floating-point constant
expressions. Example:
X := Y ~> 4
The above example shifts
right by 4 bits, maintaining the sign. If
is -3200 (%11111111
Y
Y
11111111 11110011 10000000) then
= -200 (%11111111 11111111 11111111
-3200 ~> 4
00111000). If the same operation had been done with the Shift Right operator instead, the
result would have been 268,435,256 (%00001111 11111111 11111111 00111000).
Shift Arithmetic Right has an assignment form,
, that uses the variable to its left as both
~>=
the first operand and the result destination. For example,
X ~>= 2 'Short form of X := X ~> 2
Here, the value of
is shifted right 2 bits, maintaining the sign, and the result is stored back
X
in
. The assignment form of Shift Arithmetic Right may also be used within expressions for
X
intermediate results; see Intermediate Assignments, page 253.
Random ‘
?
The Random operator is a special, immediate operator that uses a variable’s value as a seed to
create a pseudo random number and assigns that number to the same variable. It can only be
used in run-time variable expressions.
Random has two forms, forward and reverse,
depending on which side of the variable it appears on. The forward form appears to the left
of a variable and the reverse form appears to the right of a variable.
Random generates pseudo-random numbers ranging from -2,147,483,648 to +2,147,483,647.
It’s called “pseudo-random” because the numbers appear random, but are really generated by
a logic operation that uses a “seed” value as a tap into a sequence of over 4 billion essentially
random numbers. If the same seed value is used again, the same sequence of numbers is
generated. The Propeller chip’s Random output is reversible; in fact, specifically it is a 32-bit
maximum-length, four-tap LFSR (Linear Feedback Shift Register) with taps in both the LSB
(Least Significant Bit, rightmost bit) and the MSB (Most Significant Bit, leftmost bit)
allowing for bi-directional operation.
Think of the pseudo-random sequence it generates as simply a static list of over 4 billion
numbers. Starting with a particular seed value and moving forward results in a list of a
specific set of numbers. If, however, you took that last number generated and used it as the
Page 264 · Propeller Manual v1.0

Related parts for 122-32000