IF...THEN Syntax
aaron87
Posts: 6
I·notice that for IF ... THEN Syntax, all comparisons are performed using unsigned, 16-bit math. This can lead to strange results if you mix signed and unsigned numbers in IF...THEN conditions. Does anyone know how to tackle this problem, cos i need to include signed number in the IF ... THEN Syntax? thanks.
Comments
Temp1 CON -25 + 273
Temp2 CON +25 + 273
IF Celsius+273 > Temp1 AND Celsius+273< Temp2 THEN ...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
' {$PBASIC 2.5}
x VAR Word
y VAR Word
x=0
y=0
DO
· DEBUG CR,CR,"input value x: "
· DEBUGIN SDEC x
· DEBUG CR,"input value y: "
· DEBUGIN SDEC y
· IF (x-y)=>$8000 THEN···· 'check high bit - processors compare by subtracting
··· DEBUG CR,"y is greater than x"
· ELSEIF y=x THEN
··· DEBUG CR, "y=x"
· ELSE
··· DEBUG CR,"x is greater than y"
· ENDIF
LOOP
You have to include error checking to insure your highest magnitude is an absolute value of 32767. Otherwise you have anarchy or, at least, a really confused processor.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 10/4/2007 6:21:59 PM GMT