Shop OBEX P1 Docs P2 Docs Learn Events
Using the */ operator — Parallax Forums

Using the */ operator

NewzedNewzed Posts: 2,503
edited 2005-12-06 00:23 in BASIC Stamp
Here is a another little post/tutorial for the newer Stampers.· (You can tell I don't have a heck of a lot to do·smile.gif ).·

Let’s talk about using the */ operator. If you want to multiply a number by a decimal, this is the way to go.

Suppose you want to multiply 238 by 13.635. Here’s how you do it.

This is an example of the */ operator;

x = n*/$XXXX

where n is the number you want to multiply, $XXXX is the multiplier and x is the answer.

N = 238

$XXXX = 13.635 converted to a HEX number. To convert·13.635
to a HEX number:

On your Windows calculator (or any scientific calculator) convert the integer 13 to HEX = $0D.

Now for the decimal part.· To convert the .635 to HEX, multiply 256 by .635 = 162.56. Round off to nearest integer = 163.

Convert 163 to HEX = $A3. The HEX muliplier becomes $0DA3 and the above example becomes:

x = 238*/$0DA3

Let’s put this in a program:

n VAR word
x VAR word

start:

DEBUG "Enter number", cr
DEBUGIN dec n················ ·‘Enter 238 + Enter
X = n*/$0DA3
DEBUG cr, "Answer is ", dec x, cr,cr
GOTO start

If you load and run this little program, you will get an answer of 3245. In reality, 238 x 13.653 = 3245.13

That is an error of·3245.13/3245 = about·.004%. Close enough?
Of course, depending on your multiplier, it won’t always be that close, but it will be close enough for almost everything unless you’re mapping an orbit to Saturn.

You could probably do all of the above with a Stamp and forget the calculator. However suppose your decimal times 256 turned out to be 11.90. The Stamp is going to return 11, which will give you a larger error than if you did it with a calculator and rounded off to 12.

Try writing your own program using a different n and a different
multplier, then do it on a calculator and calculate your error.

Practice doesn't make you perfect but it sure helps.









▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html

·
Sign In or Register to comment.