This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to make a 32bit multiplication with 64bit result in C

How to do a 32bit multiplication with 64bit result in C?

:-)

Parents
  • you can do it with 16-bit "digits" much like you'd do it with decimal digits using pencil and paper.

    If it is the ARM (the op could not be bothered with selecting a toolset) then 32 bit "digits" will do nicely. If it is the '51 it is possible, but the calculation would take just about overnight.

    Erik

Reply
  • you can do it with 16-bit "digits" much like you'd do it with decimal digits using pencil and paper.

    If it is the ARM (the op could not be bothered with selecting a toolset) then 32 bit "digits" will do nicely. If it is the '51 it is possible, but the calculation would take just about overnight.

    Erik

Children
  • "... 32 bit "digits" will do nicely"

    If we're doing it like we'd do it by hand, 32-bit "digits" won't work because 32-bits times 32-bits would overflow. "16B" below represents a 16-bit "digit". 16-bits times 16-bits fits in a 32 integer.

               16B,16B (32-bit multiplicand)
             * 16B,16B (32-bit multiplier)
    ------------------
     +         16B,16B (32-bit partial product)
     +     16B,16B     (32-bit partial product)
     +     16B,16B     (32-bit partial product)
     + 16B,16B         (32-bit partial product)
    ==================
       16B,16B,16B,16B (64-bit product)