View Single Post
  #2   Spotlight this post!  
Unread 30-12-2002, 13:17
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
First, multiplying an 8-bit number and a 64-bit number could give you a 72-bit number if I remember my binary correctly (or maybe it's 71?). Anyway, it's going to be bigger than your original size. Well, my binary's a little rusty, as is my math thanks to winter break, but I'll give this a shot. Assuming your 64-bit number is broken up into 8 byte-sized variables named bigVar1-bigVar8 with 1 being the highest-order byte and 8 being the lowest, and assuming smallVar is your 8-bit number, the formula would look something like this:

result0 var byte
result1 var byte
...
result8 var byte
temp var word

temp=bigVar8 * smallVar
result8= temp & $00FF

temp=temp & $FF00 >> 8 + (bigVar7 * smallVar)
result7=temp & $00FF

temp=temp & $FF00 >> 8 + (bigVar6 * smallVar)
result6=temp & $00FF

temp=temp & $FF00 >> 8 + (bigVar5 * smallVar)
result5=temp & $00FF

...

temp=temp & $FF00 >> 8 + (bigVar1 * smallVar)
result1=temp & $00FF
result0=temp & $FF00 >> 8

Don't quote me on any of that as I haven't tested it yet nor do I even know how I would. Anyway, result1-result8 now have the product and result0 has whatever overflow may have occurred. Anybody want to verify this algorithm/shoot it down? As I said, it may or may not work.

Finally, I have to ask: what possible purpose could you have for a 64-bit number in PBASIC?
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php