Pretty much any variable is signed if you want. A byte can be 0-126, and anything higher, subtract 126 from it, print with a “-“ in front of it,
and is also the value of the negative number.
Pretty much any variable is signed if you want. A byte can be 0-126, and anything higher, subtract 126 from it, print with a “-“ in front of it,
and is also the value of the negative number.
But that's not really "standard" is it? I'd probably stick to the normal two's complement standard.
Subtract the value from 256 (if the variable is byte sized) and print a - in front. But really, for presentation purposes etc PBP already supports that with the SDEC modifier.
If you need to multiply two numbers (A) and (B) where one (B) can be negative thenCode:A VAR WORD B VAR WORD Sign VAR BIT A = 10 B = -5 Sign = B.15 Result = A * ABS(B) Result.15 = Sign LCDOUT SDEC Result
I had to do that, and just used an offset to make them all positive. When it comes time to use the data, I then subtract the offset from the stored number if the stored number is MORE than the offset, OR subtract the number from the OFFSET and set a "negative" flag if the stored number is LESS than the offset.
Say the range is -50 to +70. Add 50, shifting the range to 0-120. Use these "revised" values for your lookup.
Now when you do the lookup, you get a value V
If V > 49 then
V=V-50
NEGFLAG=0
else
V=50-V 'calculates the difference to restore the original data
NEGFLAG=1 'sets the negative flag so you can act upon it with calculations if needed
endif
Bookmarks