Absolute Value (Abs); Cosine (Cos); Decoder (Dcd); Inverse - Parallax BASIC Stamp 2e Programming Manual

Table of Contents

Advertisement

BASIC Stamp Architecture – ABS, COS, DCD, ~, -
The Absolute Value operator (ABS) converts a signed (two's complement)
16-bit number to its absolute value. The absolute value of a number is a
positive number representing the difference between that number and 0.
For example, the absolute value of -99 is 99. The absolute value of 99 is
also 99. ABS works on two's complement negative numbers. Examples of
ABS at work:
Result
VAR
WORD
Result = -99
DEBUG SDEC ? Result
DEBUG SDEC ? ABS Result
The Cosine operator (COS) returns the two's complement, 16-bit cosine of
an angle specified as an 8-bit (0 to 255) angle. See the explanation of the
SIN operator, below. COS is the same in all respects, except that the cosine
function returns the x distance instead of the y distance. To demonstrate
the COS operator, use the example program from SIN, below, but
substitute COS for SIN.
The Decoder operator (DCD) is a 2
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
DEBUG BIN ? Result
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 one's compliment.
For example:
Result
VAR
BYTE
Result = %11110001
DEBUG BIN ? Result
Result = ~ Result
DEBUG BIN ? Result
The Negative operator (-) negates a 16-bit number (converts to its two's
complement).
SYMBOL Result
=
W1
Result = -99
Result = Result + 100
DEBUG Result
Page 64 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com
' Put -99 (2's complement format) into Result.
' Display it on the screen as a signed #.
' Display it on the screen as a signed #.
n
-power decoder of a four-bit value.
' Set bit 12.
' Display result (%0001000000000000)
' Store bits in byte Result.
' Display in binary (%11110001).
' Complement Result.
' Display in binary (%00001110).
' Put -99 (2's complement format) into Result.
' Add 100 to it.
' Display Result (1)
A
V
: ABS
BSOLUTE
ALUE
2
2
2
2
e
sx
p
C
: COS
OSINE
2
2
2
2
e
p
sx
D
: DCD
ECODER
2
2
2
2
e
sx
p
I
: ~
NVERSE
2
2
2
2
e
sx
p
N
: -
EGATIVE
2
2
2
1
2
e
p
sx
1

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?

Table of Contents