D
.
ISPLAYING SIGNED VS
UNSIGNED
.
NUMBERS
A
UTOMATIC NAMES IN THE DISPLAY
5: BASIC Stamp Command Reference - DEBUG
Signed numbers are preceded with a space ( ) or a minus sign (-) to
indicate a positive or negative number, respectively.
number displayed by the BASIC Stamp is shown in its unsigned (positive)
form without any indicator. The signed formatters allow you to display
the number as a signed (rather than unsigned) value. NOTE: Only Word-
sized variables can be used for signed number display. The code below
demonstrates the difference in all three numbering schemes.
x
VAR
WORD
x = -65
DEBUG "Signed: ", SDEC x, " ", ISHEX x, " ", ISBIN x, CR
DEBUG "Unsigned: ", DEC x, " ", IHEX x, " ", IBIN x
This code will generate the display shown below:
Signed: -65
-$41
Unsigned: 65471
$FFBF
The signed form of the number –65 is shown in decimal, hexadecimal and
then in binary on the top line. The unsigned form, in all three number
systems, is shown on the bottom line. If the unsigned form looks strange
to you, it's because negative numbers are stored in twos-compliment
format within the BASIC Stamp.
Suppose that your program contained several DEBUG instructions
.
showing the contents of different variables. You would want some way to
tell them apart. One possible way is to do the following:
x
VAR
BYTE
y
VAR
BYTE
x = 100
y = 250
DEBUG "X = ", DEC x, CR
DEBUG "Y = ", DEC y, CR
but typing the name of the variables in quotes (for the display) can get a
little tedious. A special formatter, the question mark (?), can save you a lot
of time. The code below does exactly the same thing (with less typing):
-%1000001
%1111111110111111
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 101
Normally, any
' Show decimal value of x
' Show decimal value of y
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?