Split Multiplication of integers

前端 未结 4 1772
挽巷
挽巷 2020-12-20 07:52

I need an algorithm that uses two 32-bit integers as parameters, and returns the multiplication of these parameters split into two other 32-bit integers: 32-highest-bits par

4条回答
  •  心在旅途
    2020-12-20 08:46

    If the unsigned long type are supported, this should work:

    void umult32(uint32 a, uint32 b, uint32* c, uint32* d)
    {
      unsigned long long x = ((unsigned long long)a)* ((unsigned long long)b); //Thanks to @Толя
      *c = x&0xffffffff;
      *d = (x >> 32) & 0xffffffff;
    }
    

    Logic borrowed from here.

提交回复
热议问题