PDA

View Full Version : 32 / 16 = 16


jim
12-09-03, 04:23 PM
Hi Forth Experts,

I'm trying to do in forth

z = (x << 16)/y

where x y and z are 16 bit and the divide is 32 bit unsigned.

Can this be done easily? There seems to be the concept of "double" things but I can't find a divide.

Thanks,
-Jim

nmitech
12-09-03, 08:34 PM
( How about this, Z=X/Y
( Let assume X contains a 32-bit number,
( Y contains a 16-bit number,
( and Z is the quotient of X/Y then it must define as a double number

2VARIABLE X
VARIABLE Y
2VARIABLE Z

HEX ( let use Hex mode )
0004.4444 X 2! ( store a double number in X )
X 2@ D. 44444 OK ( check value of X to make sure )

2222 Y ! ( store a 16-bit number in Y )
Y @ U. 2222 OK ( check value of Y to make sure )

X 2@ Y @ S->D D/ Z 2! ( now divide and store the quotient in Z )
Z 2@ D. 20 OK ( check Z value )