简体   繁体   English

二进制浮点加法

[英]Binary Floating Point Addition

How does 1.000(base2) x 2^-1 + (-0.111(base2) x 2^-1) = .001(base2) x 2^-1? 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.. 我看不到加法的工作原理。

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. 它基本上以2为基数的科学计数法。

1.000(base2) x 2^-1 = 0.100(base2)
-0.111(base2) x 2^-1 = -0.0111(base2)

0.100 + (-0.0111) = 0.0001

0.0001 = 0.001(base2) x 2^-1

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 becomes 11111001 if we use 8-bit numbers for our example. 如果我们的示例使用8位数字,则-0111变为11111001

Now when you add up the numbers, 00001000+11111001=100000001 . 现在,当您将数字加起来时, 00001000+11111001=100000001 The overflow from the upper-most bit gets thrown away, leaving you with 00000001 . 最高位的溢出被丢弃,剩下00000001

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM