二进制文件签名
Prerequisite: Number systems
先决条件: 数字系统
Until now, we have only talked about positive numbers and have already discussed their mathematical operations. But there also exists negative numbers in the number system, in this article we are going to learn about how to represent negative numbers in the binary format?
到目前为止,我们仅讨论正数,并且已经讨论了它们的数学运算。 但是数字系统中也存在负数,在本文中,我们将学习如何用二进制格式表示负数?
签名号码 (Signed Numbers)
In decimal number system, we have (+) sign to represent the positive number and (-) sign to represent a negative number. But in digital logic, we have two symbols 0 and 1, so we use these symbols to represent the sign of the number.
在十进制数字系统中,我们用( + )号代表正数,用( - )号代表负数。 但是在数字逻辑中,我们有两个符号0和1 ,因此我们使用这些符号来表示数字的符号 。
There are two ways of representing signed numbers,
有两种表示带符号的数字的方式 ,
Signed Magnitude Form
签名幅度表
Complement Form
补表
1)签署幅度表 (1) Signed Magnitude Form)
In signed magnitude form, an additional bit is placed to the extreme left (MSB) of the number to represent the sign; thus, it is known as the sign bit.
在带符号的幅度形式中,在数字的最左端(MSB)处放置一个附加位来表示符号。 因此,它被称为符号位。
We use 0 to represent the positive numbers and 1 to represent the negative numbers. The extra bit is isolated from the magnitude of binary numbers using a comma.
我们用0代表正数,用1代表负数。 使用逗号将多余的位与二进制数的大小隔离。
Under the signed-magnitude system, a great amount of manipulation is required to add a positive number to a negative number. Thus, representation is possible but still, it is impractical in nature.
在有符号幅度系统下,需要大量的操作才能将正数添加到负数。 因此,表示是可能的,但在本质上仍然是不切实际的。
Example1: Represent 13 and -13 in signed magnitude form
示例1:以带符号的幅度形式表示13和-13
Solution:
解:
(13)10 = (0,1101)2 sign-bit 0 is used to represent the positive number
(-13)10 = (1,1101)2 sign-bit 1 is used to represent the negative number
Complement Form: Since performing arithmetic operations using a signed magnitude form is very complex. Digital computers use the complement form to perform these calculations.
补码形式:由于使用带符号的幅度形式执行算术运算非常复杂。 数字计算机使用补码形式来执行这些计算。
There are two complement forms - 1's complement form and 2's complement form.
有两种补码形式-1的补码形式和2的补码形式。
If the number is positive then, the magnitude is represented in its true binary form and a sign bit 0 is added to the LHS of the MSB. For a positive number, the representation is the same in signed magnitude, 1's and 2's complement form.
如果该数字为正,则以其真正的二进制形式表示幅度,并将符号位0添加到MSB的LHS。 对于正数,表示形式在带符号的幅度,1和2的补码形式上相同。
The advantage of using a complement form to perform arithmetic operations is the reduction in the hardware. Instead, of having separate hardware for addition and subtraction only additional adders are needed.
使用补码形式执行算术运算的优点是减少了硬件。 取而代之的是,没有用于加法和减法的单独硬件,仅需要附加的加法器。
1的补码表示 (1's Complement Representation)
The 1's complement of a number can be obtained by replacing each "0 bit with 1 bit" and "1 bit with 0 bit" in the binary number.
可以通过将二进制数中的每个“ 0位加1位”和“ 1位加0位”替换来获得数字的1的补码。
Example: Represent (-15)10 in its 1's complement form
示例:以其1的补码形式表示(-15) 10
Solution:
解:
(15)10 in binary form can be represented as (1111)2.
(15) 10的二进制形式可以表示为(1111) 2 。
Now, to represent its negative sign, we will add a sign bit 1.
现在,为了表示它的负号,我们将添加一个符号位1。
Thus, (-15)10 = (1,1111)2. To represent it in 1's complement form, we will replace each 1 with 0 (excluding the sign bit, because if we replace sign bit then its sign will be changed to positive which is not correct). Therefore,
因此,(-15) 10 =(1,1111) 2 。 为了用1的补码形式表示它,我们将每个1替换为0(不包括符号位,因为如果替换符号位,则其符号将变为正数,这是不正确的)。 因此,
2的补码表示 (2's Complement Representation)
We can get the 2's complement of a number by finding the 1's complement of number and adding 1 to the LSB of the respective 1's complement.
我们可以通过找到数字的1的补码并将1加到相应的1的补码的LSB上来获得数字的2的补码。
Example: Represent (-15)10 in its 2's complement form.
示例:以2的补码形式表示(-15) 10 。
Solution:
解:
As we have discussed above, the 1's complement representation of (-15)10 is given as 10000. Now, we have to add a bit 1 to the LSB in the above 1's complement form i.e., we will get,
如上所述,(-15) 10的1的补码表示为10000 。 现在,我们必须以上述1的补码形式在LSB上加一位,即,
Which is the required 2's complement representation of (-15)10.
这是(-15) 10的必填2的补码表示形式。
Example: Represent (-51)10 in its signed magnitude, 1's complement and 2's complement form.
示例:以(-51) 10的有符号幅度,1的补码和2的补码形式表示。
Solution:
解:
翻译自: https://www.includehelp.com/basics/signed-representation-of-binary-numbers.aspx
二进制文件签名