Multiplication of two 16-bit numbers - Why is the result 32-bit long? [closed]

那年仲夏 提交于 2019-12-20 07:34:50

问题


If I multiplie two 16-bit numbers, the result will be 32-bit long. But why is this so? What is the clear explanation for this?

And for my right understanding: The calculation for this is: n-bit number multiplied with a m-bit number gives a (n+m) bit number?


回答1:


(2n - 1)*(2m - 1) = 2n+m - 2n - 2m + 1

-(2n + 2m) is like clearing the bits at index n and m, which does not affect much the result compared to 2n+m, so you need n+m bits to represent the result.

For example 11112*11112 = 111000012 (15*15 = 225)

In general, (bn - 1)*(bm - 1) = bn+m - bn - bm + 1, so multiply an n-digit by an m-digit number in an arbitrary base b results in a number at most n+m digits

You can see that easily in base 10: 9*9 = 81 (1 digit * 1 digit = 2 digit) or 99*99 = 9801 (2 digit * 2 digit = 4 digit)




回答2:


For simplicity, let's take unsigned binary numbers. With n binary digits, you can represent 2^n different numbers, ranging from zero upto 2^n-1. When multiplying an n-digit binary number with an m-digit binary number, the result will be a number between zero and (2^n-1) * (2^m-1) = 2^(n+m) - 2^n - 2^m + 1, which typically is only marginally less than 2^(n+m)-1. To represent such a range of results, you need n+m binary digits.



来源:https://stackoverflow.com/questions/21416792/multiplication-of-two-16-bit-numbers-why-is-the-result-32-bit-long

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!