Shop OBEX P1 Docs P2 Docs Learn Events
Multiplication in Basic Stamp — Parallax Forums

Multiplication in Basic Stamp

Hello All,

I am looking for some clarification.

I am trying to multiply a variable by 2*10^-2

I have gone through all the help, teacher notes I have, books, and discussions but I am still not sure how to write it correctly.

'{$STAMP BS2}
'{$PBASIC 2.5}

BS VAR Word
time VAR Word

PAUSE 1000
DO

HIGH 7
PAUSE 100
RCTIME 7, 1, BS
DEBUG HOME, "BS# = ", DEC5 BS
time = BS */ 'what here?
DEBUG ? time

LOOP

Any help or clarification anyone could supply would be much appreciated.

Comments

  • First of all, let's be sure we understand what you want to do:

    2*10^-2 to me means 2/100 or 0.02

    Is that what you mean?

    Secondly, the Stamps store numbers either as 8-bit unsigned values (from 0 to 255) or as 16-bit signed values (from -32768 to +32767). Clearly, neither of these can be used directly for fractional values like 2/100. You will need to scale your values. For that, you'll have to describe what range of values you want to use. For example, you might want to use 16-bit integers and scale so your units are 0.01. Your range then would be -327.68 to +327.67

    Is this what you have in mind?

Sign In or Register to comment.