Simple Math Question.
Downs
Posts: 30
Hi,
How do you get the BASIC STAMP 2 to multiply a value with 48.92? I tried using Value1 */ $48EB but that's not correct. 48 being the upper byte and Taking .92 * 256 = 235 = ($EB) for the lower byte. I'm lost somewhere! Any help would be greatly appreciated. Thank you.
How do you get the BASIC STAMP 2 to multiply a value with 48.92? I tried using Value1 */ $48EB but that's not correct. 48 being the upper byte and Taking .92 * 256 = 235 = ($EB) for the lower byte. I'm lost somewhere! Any help would be greatly appreciated. Thank you.
Comments
Thanks,
DJ
x * 5.2
= x */ ( 5.2 * 256 )
= x */ 1331 (decimal) or
result = x */ $533
Basically, for a mid-multiply, 5.2 = ( 5 * 256 ) + ( .2 * 256 )
If you are multiplying by a fraction less than 1, high-multiply gives more precision. It's basically the same thing but with $FFFF (65535 decimal):
x * .2
= x ** ( .2 * 65535 )
= x ** 13107 (decimal)
result = x ** $3333
Neither of these simple examples takes into account rounding... a better explicit mid-multiply might go something like this:
x * 5.2
= x */ (5.2 * 256)
result = ( (x * $533) + 128 ) / 256
Which takes into account rounding during the divide by 256 (mid-multiply does the exact same thing as above in 32bit math space, but doesn't add the 128 for rounding).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 1/13/2009 11:08:24 PM GMT
DJ