Adding 64 bit numbers using 32 bit arithmetic

前端 未结 6 879
渐次进展
渐次进展 2020-12-05 06:02

How do we add two 64 bit numbers using 32 bit arithmetic??

6条回答
  •  独厮守ぢ
    2020-12-05 06:26

    If the 64-bit numbers are (a2,a1) and (b2,b1), where x2 is the high 32 bits taken as unsigned, and x1 is the low 32 bits taken as unsigned, then the sum of the two numbers is given below.

    c1 = a1 + b1
    
    c2 = a2 + b2
    
    if (c1 < a1 || c1 < b1)
       c2 += 1
    

提交回复
热议问题