Shop OBEX P1 Docs P2 Docs Learn Events
Having problems with SX/B and divide by 1000 — Parallax Forums

Having problems with SX/B and divide by 1000

mardormardor Posts: 3
edited 2008-01-28 01:46 in General Discussion
I have a WORD variable with value 2400 and when I device by 1000
and assign the __REMAINDER I get an incorrect value.

This breaks....

ORIG VAR WORD
WHOLE VAR WORD
FRAC VAR WORD

ORIG = 2400
WHOLE = ORIG / 1000
FRAC = __REMAINDER

I end up with WHOLE=2
and FRAC=144

This works....

ORIG VAR WORD
WHOLE VAR WORD
FRAC VAR WORD
TEMP VAR WORD

ORIG = 2400
WHOLE = ORIG / 1000
TEMP = WHOLE * 1000
FRAC = ORIG - TEMP

I end up with WHOLE=2
and FRAC=400

Comments

  • JonnyMacJonnyMac Posts: 9,218
    edited 2008-01-28 00:24
    You have to use __WREMAINDER to get a 16-bit remainder. This works:

    Main:
      value = 2400
      whole = value / 1000
      frac = __WREMAINDER
    
      WATCH whole, 16, sdec
      WATCH frac, 16, sdec
      BREAK
    
      GOTO Main
    
  • mardormardor Posts: 3
    edited 2008-01-28 01:46
    Thanx a thousand....That did the trick.
Sign In or Register to comment.