Subj : Re: puzzle little closer to machine. To : comp.programming From : CBFalconer Date : Mon Jul 04 2005 07:01 pm Jack Klein wrote: > unknown@this-world.com wrote in comp.programming: > >> Can somebody solve the following puzzle ? >> >> Suppose I have a 32 bit machine with 32 bit 32 registers. >> How to multiply two integers in such a machine with taking >> care of all the overflows. Also MUL or such multiplication >> operands are not available in such a machine. > > I don't need luck, I know how to do it. In fact, I've written 32 > x 32 multiply routines that produced correct 64 bit results on 8 > and 16 bit machines. > > The basic binary multiplication algorithm requires only shifts and > adds, and I assume your 32 bit processor provides both of those. In addition, the 32*32 -> 64 multiplication can NEVER create an overflow. Any possible problems arise later, when trying to stuff a 64 bit entity into a 32 bit pot. If it doesn't fit you must act on it. -- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson .