Hallo to everyone.
My problem is to have the upper 4 Byte result of a multiply. For example:
unsigned int a=1000000000;//only example value unsigned int b=10000000000; unsigned int c;
the result of a*b = 0x8AC7230489E80000 How to get the upper 4 Bytes: 0x8AC72304 How to get the lower 4 Bytes: 0x89E80000
Can anybody help? I have to programm a super-fast-interrupt-routine for an microcontroller, there is not enough time for floating point.
union U64_ { unsigned long long ull; unsigned long ul[2]; }; unsigned long multiplier; unsigned long multiplicand; union U64_ product; unsigned long product_msl; unsigned long product_lsl; product.ull = (unsigned long long)multplicand * multiplier; product_msl = product.ul[1]; /* Assuming little-endian */ product_lsl = product.ul[0]; /* Assuming little-endian */
Quickly typed, not tested :-(
s/multplicand/multiplicand/