浮点数在计算机中的表示和存储

è¿éåå¾çæè¿°

 

Floating Point Representation | Digital Logic

1. To convert the floating point into decimal, we have 3 elements in a 32-bit floating point representation:
    i) Sign
    ii) Exponent
    iii) Mantissa

  • Sign bit is the first bit of the binary representation. '1' implies negative number and '0' implies positive number.
    Example: 11000001110100000000000000000000 This is negative number.
  • Exponent is decided by the next 8 bits of binary representation. 127 is the unique number for 32 bit floating point representation. It is known as bias. It is determined by 2k-1 -1 where 'k' is the number of bits in exponent field.

    There are 3 exponent bits in 8-bit representation and 8 exponent bits in 32-bit representation.
    Thus
    bias = 3 for 8 bit conversion (23-1 -1 = 4-1 = 3)
    bias = 127 for 32 bit conversion. (28-1 -1 = 128-1 = 127)

    Example: 01000001110100000000000000000000
    10000011 = (131)2
    131-127 = 4

    Hence the exponent of 2 will be 4 i.e. 24 = 16.

  • Mantissa is calculated from the remaining 23 bits of the binary representation. It consists of '1' and a fractional part which is determined by:

    Example:

    01000001110100000000000000000000

    The fractional part of mantissa is given by:

    1*(1/2) + 0*(1/4) + 1*(1/8) + 0*(1/16) +……… = 0.625

    Thus the mantissa will be 1 + 0.625 = 1.625

    The decimal number hence given as: Sign*Exponent*Mantissa = (-1)*(16)*(1.625) = -26

2. To convert the decimal into floating point, we have 3 elements in a 32-bit floating point representation:
    i) Sign (MSB)
    ii) Exponent (8 bits after MSB)
    iii) Mantissa (Remaining 23 bits)

Thus the floating point representation of -17 is 1 10000011 00010000000000000000000

  • Sign bit is the first bit of the binary representation. '1' implies negative number and '0' implies positive number.
    Example: To convert -17 into 32-bit floating point representation Sign bit = 1
  • Exponent is decided by the nearest smaller or equal to 2n number. For 17, 16 is the nearest 2n. Hence the exponent of 2 will be 4 since 24 = 16. 127 is the unique number for 32 bit floating point representation. It is known as bias. It is determined by 2k-1 -1 where 'k' is the number of bits in exponent field.

    Thus bias = 127 for 32 bit. (28-1 -1 = 128-1 = 127)

    Now, 127 + 4 = 131 i.e. 10000011 in binary representation.

  • Mantissa: 17 in binary = 10001.

    Move the binary point so that there is only one bit from the left. Adjust the exponent of 2 so that the value does not change. This is normalizing the number. 1.0001 x 24. Now, consider the fractional part and represented as 23 bits by adding zeros.

    00010000000000000000000

Related Link:
https://www.youtube.com/watch?v=03fhijH6e2w
More questions on number representation:
http://quiz.geeksforgeeks.org/number-representation/

This article is contributed by Kriti Kushwaha

 

 

 

Floating point representation - IEEE 754

https://www.youtube.com/watch?v=hoEP6Qk9kfU

 

 

Floating Point Basics

https://chi_gitbook.gitbooks.io/personal-note/content/floating_point_basic.html

 

浮点数在计算机中是如何存储的?

float和double的存储范围和,精度,存储的问题

https://leokongwq.github.io/2017/08/19/computer-how-float-stored.html

 

基础野:细说浮点数

https://yq.aliyun.com/articles/32191#

 

整数和浮点数的在计算机中的表示以及运算

https://www.zybuluo.com/XingdingCAO/note/787884

 

IEEE 754——计算机中浮点数的表示方法

https://blog.csdn.net/lanchunhui/article/details/50662458

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值