BASIC Stamp Architecture – SQR
Page 66
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
To convert brads to degrees, multiply by 180 then divide by 128. To
convert degrees to brads, multiply by 128, then divide by 180. Here’s a
small program that demonstrates the SIN operator:
Degr VAR WORD ' Define variables.
Sine VAR WORD
FOR Degr = 0 TO 359 STEP 45 ' Use degrees.
Sine = SIN (Degr * 128 / 180) ' Convert to brads, do SIN.
DEBUG "Angle: ", DEC Degr, TAB, "Sine: ", SDEC Sine, CR ' Display.
NEXT
The Square Root operator (SQR) computes the integer square root of an
unsigned 16-bit number. (The number must be unsigned since the square
root of a negative number is an ‘imaginary’ number.) Remember that most
square roots have a fractional part that the BASIC Stamp discards when
doing its integer-only math. So it computes the square root of 100 as 10
(correct), but the square root of 99 as 9 (the actual is close to 9.95).
Example:
DEBUG SQR 100 ' Display square root of 100 (10).
DEBUG SQR 99 ' Display of square root of 99 (9 due to truncation)
Table 4.6 lists the available Binary (two-argument) Operators.
Operator
Description
Supported By:
+
Addition
All
-
Subtraction
All
*
Multiplication
All
**
Multiplication (returns upper 16-bits)
All
*/
Multiply by 8-bit integer, 8-bit fraction
All except BS1
/
Division
All
//
Modulus (Remainder of division)
All
MIN
Limits a value to a specified low
All
MAX
Limits a value to a specified high
All
DIG
Returns specified digit of number
All except BS1
<<
Shift bits left by specified amount
All except BS1
>>
Shift bits right by specified amount
All except BS1
REV
Reverse specified number of bits
All except BS1
&
Bitwise AND
All
|
Bitwise OR
All
^
Bitwise XOR
All
&/
Logical AND NOT
Only BS1
|/
Logical OR NOT
Only BS1
^/
Logical XOR NOT
Only BS1
2
e
2
sx
2
p
2
S
QUARE
R
OOT
: SQR
B
INARY
O
PERATORS
.
Table 4.6: Binary Operators. Note:
some binary operators are not
supported by all BASIC Stamps.
Summary of Contents for BASIC Stamp 2e
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...