BASIC stamp manual v2.2

BASIC Stamp Architecture – COS, DCD, ~, -
Page 106 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
result VAR Word
result = -99 ' Put -99 into result
' ...(2's complement format)
DEBUG SDEC ? result ' Display as a signed #
DEBUG SDEC ? ABS result ' Display as a signed #
The Cosine operator (COS) returns the two’s complement, 16-bit cosine of
an angle specified as an 8-bit “binary radian” (0 to 255) angle. COS is the
same as SIN in all respects, except that the cosine function returns the x
distance instead of the y distance. See “Sine: SIN”, below, for a code
example and more information.
The Decoder operator (DCD) is a 2
n
-power decoder of a four-bit value.
DCD accepts a value from 0 to 15, and returns a 16-bit number with the
bit, described by value, set to 1. For example:
result VAR Word
result = DCD 12 ' Set bit 12
DEBUG BIN16 ? result ' Display result (%0001000000000000)
The Inverse operator (~) complements (inverts) the bits of a number. Each
bit that contains a 1 is changed to 0 and each bit containing 0 is changed to
1. This process is also known as a “bitwise NOT” and “ones complement”.
For example:
result VAR Byte
result = %11110001 ' Store bits in byte result.
DEBUG BIN8 ? result ' Display in binary (%11110001)
result = ~ result ' Complement result
DEBUG BIN8 ? Result ' Display in binary (%00001110)
The Negative operator (-) negates a 16-bit number (converts to its twos
complement).
SYMBOL result = W1
result = -99 ' Put -99 into result
' ...(2's complement format)
result = result + 100 ' Add 100 to it
DEBUG result ' Display result (1)
-- or --
C
OSINE: COS
D
ECODER: DCD
N
EGATIVE: -
All
2
All
2
1
INVERSE: ~