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
  • "... 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)

Reply
  • "... 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)

Children
No data