二進制文件簽名
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
二進制文件簽名