PDA

View Full Version : negatives



Kamikaze47
- 29th April 2007, 15:16
If I subtract 1 from a variable that currently has a value of 0 what will the result be? 0? 255? or something else?

mister_e
- 29th April 2007, 15:17
if it's a BYTE... yes it will be 255.

Kamikaze47
- 29th April 2007, 15:21
thanks mister_e

Darrel Taylor
- 29th April 2007, 20:29
Depends on how you want to look at it.
It can also be -1

X VAR BYTE

X = 0
X = X - 1

LCDOUT SDEC X
Displays -1 on LCD
<br>

sougata
- 30th April 2007, 07:30
If any are preceded by an S (for signed), the output will be sent
preceded by a “-“ if the high order bit of the data is set. This allows the
transmission of negative numbers. Keep in mind that all of the math
and comparisons in PBP are unsigned. However, unsigned math can
yield signed results. For example, take the case of B0 = 9 - 10.
The result of DEC B0 would be “255". Sending SDEC B0 would give “-
1" since the high order bit is sent. So with a little trickery, the unsigned
math of PBP can yield signed results.

sougata
- 30th April 2007, 07:37
Thanks Darrel. This second post is because I have always skipped that portion of the manual and done it in hard way. Thanks again.

Darrel Taylor
- 30th April 2007, 09:58
I never knew that

Can't say that anymore. :D

Glad to help.
<br>