122-28029 Parallax Inc, 122-28029 Datasheet - Page 93

GUIDE STUDENT SMART SENSORS

122-28029

Manufacturer Part Number
122-28029
Description
GUIDE STUDENT SMART SENSORS
Manufacturer
Parallax Inc
Datasheet

Specifications of 122-28029

Accessory Type
Manual
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Contains lead / RoHS non-compliant
For Use With/related Products
Smart Sensors
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Contains lead / RoHS non-compliant
The pattern emerges when you can see an unsigned decimal number compared next to its
signed decimal and binary equivalents.
' Smart Sensors and Applications - SignedNumbers.bs2
' {$STAMP BS2}
' {$PBASIC 2.5}
x
x = 32768
DEBUG "you entered decimal: ", DEC x, CR
DEBUG "signed decimal: ", SDEC x, CR
DEBUG "16-bit binary: ", BIN16 x, CR
In PBASIC, only word variables can hold signed numbers, so all signed numbers have 16
bits. By looking at the leftmost bit, Bit 15, we can know whether a signed number is
negative or positive. You can use
value
positive. If it is equal to 1, the number is negative.
This is an important hint, because some PBASIC operators only work with positive
integers, such division "
save the sign of a number, perform the operation with its absolute value, then reapply the
sign afterwards. In fact, we will be doing that later in Chapter 4.
VAR
is a positive or negative number. If
Figure 3-12: Two’s Complement Signed Decimal Number Line
-32768...............-1...0...1...............32767
Try running SignedNumbers.bs2 with different values for
becomes clear to you. Try these
Then try 65535, 65534, 32767, 32768, and 32769. Do you see how it works?
Word
|
|
|
1000000000000000 (DEC 32768)
'<<< Enter new values for x here, and re-run the program
(DEC 1)0000000000000001
/
" and modulus "
(DEC 32767)0111111111111111
value.BIT15
|
1111111111111111(DEC 65535)
x
//
Chapter 3: Tilt with the Memsic Accelerometer · Page 81
values: 0, 1, 2, -1, -2.
". When using these operators, it is handy to
value.BIT15
|
as a variable that tells you whether
is equal to 0, the number is
x
until the pattern
|
|
|

Related parts for 122-28029