二进制浮点加法
1.000(base2) x 2^-1 + (-0.111(base2) x 2^-1) = .001(base2) x 2^-1 如何计算? 二进制数相加不就是简单的相加吗?我不明白添加是如何工作的..
How does 1.000(base2) x 2^-1 + (-0.111(base2) x 2^-1) = .001(base2) x 2^-1?
To add binary numbers don't you simply just add? I'm not seeing how the addition works..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当你问“你不只是简单地相加吗?”时,我不确定你的意思是什么,但数学是正确的。它基本上采用以 2 为底的科学记数法。
I'm not sure what you mean when you ask "don't you simply just add?", but the math is correct. It is basically in base-2 scientific notation.
浮点数的情况要复杂得多。让我们从整数开始。
要将正数变为负数,请将所有位反转并加一。这称为“补码”算术。如果我们在示例中使用 8 位数字,则
-0111
变为11111001
。现在,当您将数字相加时,
00001000+11111001=100000001
。最上面位的溢出被丢弃,留下00000001
。Things are a lot more complicated with floating point numbers. Let's start with integers.
To turn a positive number into a negative, you invert all the bits and add one. This is called "two's complement" arithmetic.
-0111
becomes11111001
if we use 8-bit numbers for our example.Now when you add up the numbers,
00001000+11111001=100000001
. The overflow from the upper-most bit gets thrown away, leaving you with00000001
.