Shop OBEX P1 Docs P2 Docs Learn Events
32 bit integers — Parallax Forums

32 bit integers

Tristan TTristan T Posts: 31
edited 2006-06-05 23:36 in BASIC Stamp
Hello,
I was wondering if there is a graceful way to represent 32 bit integers on the basic stamp, specifically the BS2px. I have a navigation sensor that returns 2800 counts per meter, so I quickly run into the (2^16)/2 limit. I would prefer not to simply dump 2 significant figures, because the refresh rate of the sensor is very quick, returning very small values that I sum into my TotalX variable. At given intervals I take the TotalX figure and ** it by a scalar to get a meter representation of the distance traveled.

Suggestions?

Thank you in advance,
Tristan.

Comments

  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-06-05 22:59
    You can always span data across multiple variables- like you can create a word from two bytes, etc. The trick is in keeping the code clean such that the 'assembly' of the two halves is done correctly.

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
  • Tristan TTristan T Posts: 31
    edited 2006-06-05 23:09
    I suppose I was asking for an "easier" solution than that, although it isn't too bad.

    Is there a hardware limitation to the number of bits that can be assigned to a single variable name, or is it just a limitation of PBASIC? I understand that a PIC is only 8 bits, but if PBASIC supports 16bit words, then it would appear that the 16 bit maximum is just a support choice rather than a real limitation. I'm studying mechanical engineering so please forgive my ignorance of microcontrollers.

    -Tristan
  • Tristan TTristan T Posts: 31
    edited 2006-06-05 23:36
    I feel silly replying to my own comment, but posted in another thread was this guide to 32 bit math for the BS2:

    http://www.emesystems.com/BS2math6.htm

    Hopefully it will be easier to find with this thread name for other people looking for 32 bit integer operations.
    -Tristan
Sign In or Register to comment.