天天看点

二进制表示浮点数_二进制数的浮点表示

二进制表示浮点数

Prerequisite:

Number systems

先决条件:

数字系统

We all very well know that very small and very large numbers in the decimal number system are represented using scientific notation form by stating a number (

mantissa

) and an exponent in the power of

10

. Some of the examples are

6.27 * 10-27 and 5.21 * 1034

. Similarly, Binary numbers can also be represented in the same form by stating a number (

mantissa

) and an exponent of

2

. The format of this representation will be different for different machines.

众所周知,十进制数系统中的非常小和非常大的数字都是用科学计数形式表示的,即数字(

尾数

)和幂为

10

的指数。 一些示例是

6.27 * 10 -27和5.21 * 10 34

。 类似地,二进制数字也可以通过表示数字(

尾数

)和

2

的指数来以相同的形式表示。 对于不同的机器,此表示形式的格式将有所不同。

The 16-bit machine consists of 10 bits as the

mantissa

and 6 bits for the

exponent

part whereas 24-bit machine consists of 15 bits for mantissa and 9 bits for exponent.

16位机器由10位

尾数

组成,

指数

部分为6位,而24位机器由尾数15位组成,

指数

部分为9位。

Format of the 16-bit machine can be represented as:

16位计算机的格式可以表示为:

Mantissa Part Exponent Part
0110011010 101010
尾数部分 指数部分
0110011010 101010

The

mantissa

is written in 2's complement form, so the

MSB of the Mantissa

can be thought of as a sign bit. The binary point is assumed to be to the right of this sign bit. The 6-bit of the exponent can be used to represent

0 to 63

, however, to express negative exponents a number

(32)10

or

(100000)2

is added to the desired exponent.

尾数

以2的补码形式编写,因此可以将

尾数

MSB

视为符号位。 假定二进制点在该符号位的右边。 指数的6位可用于表示

0到63

,但是,要表示负指数,则将数字

(32) 10

(100000) 2

添加到所需的指数。

Excess-32 Representation

: This is a common system to represent floating-point numbers. In this notation, to represent a negative exponent, we add

(32)10

to the given exponent which are given by the 6 bits.

Excess-32表示法

:这是表示浮点数的通用系统。 在这种表示法中,为了表示负指数,我们将

(32) 10

加到由6位给出的给定指数上。

Given table illustrates representation of exponent part.

给定的表说明了指数部分的表示。

Desired Exponent 2's complement notation Excess-32 notation (in 6 bits) Binary representation
-32 100000 100000 +100000 = 000000 000000
-31 100001 100001 +100000 = 000001 000001
-30 100010 100010 +100000 = 000010 000010
-15 110001 110001 +100000 = 010001 010001
000000 000000 +100000 = 100000 100000
+1 000001 000001 +100000 = 100001 100001
+15 001111 001111 +100000 = 101111 101111
+30 011110 011110 +100000 = 111110 111110
+31 011111 011111 +100000 = 111111 111111
期望指数 2的补码表示法 多余的32位表示法(6位) 二进制表示
-32 100000 100000 +100000 = 000000 000000
-31 100001 100001 +100000 = 000001 000001
-30 100010 100010 +100000 = 000010 000010
-15 110001 110001 +100000 = 010001 010001
000000 000000 +100000 = 100000 100000
+1 000001 000001 +100000 = 100001 100001
+15 001111 001111 +100000 = 101111 101111
+30 011110 011110 +100000 = 111110 111110
+31 011111 011111 +100000 = 111111 111111
Mantissa Part Exponent Part
0110011010 101010
尾数部分 指数部分
0110011010 101010

As given above, the

floating-point number

given in the above format is:

如上所述,以上述格式给出的

浮点数

为:

At the extreme left (

MSB

) is the

sign-bit '0'

, which represents it is a positive number. Also, just after the sign-bit, we assume a binary point. Thus,

最左端(

MSB

)是

符号位“ 0”

,表示它是一个正数。 同样,在符号位之后,我们假设一个二进制点。 从而,

In Mantissa Part: .110011010
    In Exponent Part:  101010, In Excess-32 notation,32 is already added. So
    Subtracting 100000   001010 (i.e.,10 in decimal, so exponent part is 210)
    The number is N
        = +(.110011010)2 * 210
        = +(1100110100.00)
        = +(820)10
           
Example 1: Express the following decimal number into 16-bit floating point number (45365.125)10 示例1:将以下十进制数表示为16位浮点数(45365.125) 10 Solution: 解:
Binary equivalent of (45365.125)10: 1011000100110101.001
    Binary format: .1011000100110101 * 216
    Mantissa: + .101100010
    Exponent: 010000 (Value of exponent is 16)
    Equivalent exponent: 010000 + 100000 = 110000
           

Since the number is a positive number an additional sign-bit '0' is added in the

MSB

.

由于该数字为正数,因此在

MSB中

添加了一个附加符号位“ 0”。

So, the floating-point format will be

0101100010110000

因此,浮点格式将为

0101100010110000 Example 2: What floating point number do the given number 0100101001101011 represents? 示例2:给定的数字0100101001101011代表什么浮点数? Solution: 解:

At the extreme left (MSB) is the sign-bit '0' which represents it is a positive number. Also, just after the sign-bit we assume a binary point. Thus,

最左边(MSB)是符号位“ 0”,表示它是一个正数。 同样,在符号位之后,我们假设一个二进制点。 从而,

In Mantissa Part: .100101001
    In Exponent Part: 10101, In Excess-32 notation,32 is already added. So
    Subtracting 100000 001011 (i.e.,11 in decimal, so exponent part is 211)
    The number is N 
        = +(.100101001)2 * 211
        = +(10010100100.0)
        = +(1188)10
           
翻译自: https://www.includehelp.com/basics/floating-point-representation-of-binary-numbers.aspx

二进制表示浮点数