EasyManua.ls Logo

Parallax BASIC Stamp 2e - Square Root (SQR); Binary

Default Icon
353 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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
SQUARE ROOT: SQR
B
INARY OPERATORS.
Table 4.6: Binary Operators. Note:
some binary operators are not
supported by all BASIC Stamps.

Table of Contents

Related product manuals