Shop OBEX P1 Docs P2 Docs Learn Events
Multiply High? — Parallax Forums

Multiply High?

crgwbrcrgwbr Posts: 614
edited 2006-10-12 12:36 in BASIC Stamp
I have been looking and looking, but I can't find much info on the Multiply High command, **.· I need to take the number 0.351 (or at least 0.35) and multiply it by a variable, ENCODE.· I believe the ** operater is the only way to de this.· Could someone demonstrait using it, or point me somewhere that has a good explanation.

Thanks

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-12 00:14
    The PBasic Manual has an explanation on page 111. This returns the upper 16 bits of a 32 bit multiply result. Assuming ENCODE is an integer, you could multiply ENCODE by 0.351 and get an integer result. The trick is to convert 0.351 into a 16 bit value with the "binary point" to the left of the 16 bits. For example, 0.5 would be $8000, 0.25 would be $4000, 0.125 would be $2000, 0.0625 would be $1000 and 0.03125 would be $0800. With this, 0.34375 would be $5800, so ENCODE ** $5800 would give you the equivalent of ENCODE times 0.34375 as an integer value.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-10-12 04:52
    I can point you to emesys.com/BS2math1.htm.

    Like Mike says, first convert 0.351 to a binary fraction, 351/1000 = factor/65536.
    factor = 65536* 351/1000 = 23003 ' solved on a calculator

    then in pbasic...

    result = 23003 ** encode ' same as 0.351 * encode

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • crgwbrcrgwbr Posts: 614
    edited 2006-10-12 11:21
    Thanks, that helped a lot. I had tried understanding the BS2 Editor's Index explination, way to complex.

    Thanks Again
    crgwbr

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    NerdMaster
    For
    Life
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-10-12 12:36
    crgwbr -

    You may find this to be an exceptionally good source of information for advanced math application in the PBASIC Stamp including the ** and */ operators:
    http://www.emesystems.com/BS2index.htm#math

    Thanks go to Dr. Tracy Allen, the author of that web site, and Stamp Math Guru!

    Regards,

    Bruce Bates
Sign In or Register to comment.