This message is in MIME format which your mailer apparently does not support. You either require a newer version of your software which supports MIME, or a separate MIME decoding utility. Alternatively, ask the sender of this message to resend it in a different format. --692626696--2145098280--1675635683 Content-Type: text/plain; charset=us-ascii Hi all, I've attached some code I've been working on - a simple multiple-precision maths library written in C. I've got the add/subtract/multiply/divide stuff working, but I'm having a hard time finding some information on alternative multiplication and division routines. At the moment, the code uses a brute-force (repeated subtraction) division routine and a very nasty multiplication routine. I'd like to get rid of the 16-bit multiply in the multiplication routine and find a faster division routine. On a PC, it doesn't really matter how inefficient the code is, simply due to the high speeds of the CPUs in most modern PCs. The catch is, when I run this code on a PIC, every cycle counts. I've heard about a set of routines that use shifts, adds and subtracts to perform division and multiplication, but I can't find any usable information on them (i.e. pseudocode). Has anyone ever done anything like this? Thanks. -- Phil. | Acorn Risc PC600 Mk3, SA202, 64MB, 6GB, philpem@dsl.pipex.com | ViewFinder, 10BaseT Ethernet, 2-slice, http://www.philpem.dsl.pipex.com/ | 48xCD, ARCINv6c IDE, SCSI ... Sorry... my mind has a few bad sectors. -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details. --692626696--2145098280--1675635683 Content-Type: application/riscos; name="BIGNUM.C,b18"; type=&b18; load=&fffb184c; exec=&8fa1d9a8; access=&403 Content-Disposition: attachment; filename="BIGNUM.C" Content-Transfer-Encoding: base64 I2luY2x1ZGUgPHN0cmluZy5oPg0KI2luY2x1ZGUgPHN0ZGlvLmg+DQojaW5jbHVkZSA8 Y29uaW8uaD4NCg0KLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8v Ly8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLw0KDQovLyBTaXplIG9m IGEgQklHTlVNIGluIGJpdHMNCiNkZWZpbmUgQklUQ09VTlQJMzINCi8vIFNpemUgb2Yg YSBCSUdOVU0gaW4gYnl0ZXMsIGF1dG9jYWxjdWxhdGVkIA0KI2RlZmluZSBCW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