We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
How to do a 32bit multiplication with 64bit result in C? :-)
C does not have a 64bit data type, you mustv code it. Erik
There are several threads in the forum with a link to C++ source for 64-bit arithmetic using a compiler that only supports 32 bit integers. Conversion to C is fairly straightforward.
If your compiler supports 64-bit long-longs, you're done. If not, you can do it with 16-bit "digits" much like you'd do it with decimal digits using pencil and paper.
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
"... 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)