BASIC stamp manual v2.2

BASIC Stamp Architecture – **, */
Page 112 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
multiply the fraction part by 65536. For example, 0.72562 is represented by
47554, which is 0.72562 * 65536.
SYMBOL Frac = 47554 ' = 0.72562 x 65536
SYMBOL value = W0
value = 10000
value = value ** Frac ' Multiply 10000 by 0.72562
DEBUG value ' Show result (7256)
-- or –
Frac CON 47554 ' = 0.72562 x 65536
value VAR Word
value = 10000
value = value ** Frac ' Multiply 10000 by 0.72562
DEBUG ? value ' Show result (7256)
The Multiply Middle operator (*/) multiplies variables and/or constants,
returning the middle 16 bits of the 32-bit result. This has the effect of
multiplying a value by a whole number and a fraction. The whole number
is the upper byte of the multiplier (0 to 255 whole units) and the fraction is
the lower byte of the multiplier (0 to 255 units of 1/256 each). The */ (star-
slash) instruction gives you an excellent workaround for the BASIC
Stamp's integer-only math. Suppose you want to multiply a value by 1.5.
The whole number, and therefore the upper byte of the multiplier, would
be 1, and the lower byte (fractional part) would be 128, since 128/256 = 0.5.
It may be clearer to express the */ multiplier in hex—as $0180—since hex
keeps the contents of the upper and lower bytes separate. Here's an
example:
value1 VAR Word
value1 = 100
value1 = value1*/ $0180 ' Multiply by 1.5 [1 + (128/256)]
DEBUG ? value1 ' Show result (150)
To calculate the constant for use with the */ operator, multiply the target
(mixed) value by 256 and convert to an integer. For instance, take Pi (π,
3.14159). The */ constant would be INT(3.14159 * 256) = 804 ($0324). So
the constant Pi for use with */ would be $0324. This isn’t a perfect match
for Pi, but the error is only about 0.1%. Note that the */ operator can be
used to multiply by mixed values up to about 255.996.
MULTIPLY MIDDLE: */
1
All
2
All
2
All
2