BASIC Stamp Architecture – SQR
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
Sine
VAR
WORD
FOR Degr = 0 TO 359 STEP 45
Sine = SIN (Degr * 128 / 180)
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
DEBUG SQR 99
Table 4.6 lists the available Binary (two-argument) Operators.
Operator
+
Addition
-
Subtraction
*
Multiplication
**
Multiplication (returns upper 16-bits)
*/
Multiply by 8-bit integer, 8-bit fraction
/
Division
//
Modulus (Remainder of division)
MIN
Limits a value to a specified low
MAX
Limits a value to a specified high
DIG
Returns specified digit of number
<<
Shift bits left by specified amount
>>
Shift bits right by specified amount
REV
Reverse specified number of bits
&
Bitwise AND
|
Bitwise OR
^
Bitwise XOR
&/
Logical AND NOT
|/
Logical OR NOT
^/
Logical XOR NOT
Page 66 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com
' Display square root of 100 (10).
' Display of square root of 99 (9 due to truncation)
Description
' Define variables.
' Use degrees.
' Convert to brads, do SIN.
Supported By:
All
All
All
All
All except BS1
All
All
All
All
All except BS1
All except BS1
All except BS1
All except BS1
All
All
All
Only BS1
Only BS1
Only BS1
S
R
: SQR
QUARE
OOT
2
2
2
2
e
sx
p
B
O
.
INARY
PERATORS
Table 4.6: Binary Operators. Note:
some binary operators are not
supported by all BASIC Stamps.
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?