转载--C语言:浮点数在内存中的表示

单精度浮点数: 1位符号位   8位阶码位   23位尾数

双精度浮点数: 1位符号位   8位阶码位   52位尾数

 

实数在内存中以规范化的浮点数存放,包括数符、阶码、尾数。数的精度取决于尾数的位数。比如32位机上float型为23位       double型为52位。

单精度float型存储在内存中的大小为4个字节,即32位。

浮点表示的一般形式为:R=M*2^e (R:Real       M:Mantissa尾数     e:exponent阶码)

把上面float的二进制可分成三部分:

   x                   xxxxxxxx             xxxxxxxxxxxxxxxxxxxxxxx

数符(1b)         阶码(8b)         尾数(23b)

double型的浮点数分别是:数符(1b)、阶码(8b)、尾数(52b)

数符sign:real的正负号     "+":0        "-":1

阶码e:e=E-127(double型中e=E-1023) e为正值说明这个浮点数向左移动了e位, e为负值说明这个浮点数向右移动了e位。127=2^7-1 1023=2^10-1

尾数M:有效数字位,这里是有效数字位的部分二进制码

例1:float型浮点数125.5转化成32位二进制浮点数

125.5的二进制码为1111101.1,写成二进制的科学计数为:1.1111011*2^6(因为科学计数法“整数”部分大于1,在二进制中,“整数”部分只能恒为1)即向左移6位,则e=6,则E=e+127=133,而E的二进制码为10000101,而1.1111011把“整数”部分去除1之后为1111011,之后补0,共23b,形成了阶码。

所以125.5的32位二进制浮点数为

0 10000101 11110110000000000000000

例2:float型浮点数0.5转化成32位二进制浮点数

0.5的二进制码为0.1,写成二进制的科学计数为:1.0*2^(-1)即向右移1位,则e=-1,则E=e+127=126,而E的二进制码为01111110,而1.0把“整数”部分去除1之后为0,之后补0,形成了阶码。

 

所以0.5的32位二进制浮点数为

0 01111110 00000000000000000000000

double型浮点数类似。

例3:32位二进制浮点数为0 10000010 00010000000000000000000转化成十进制数浮点数

题中已给我们分了三部分,数符部分、阶码部分、尾数部分。

数符部分为0,则代表此数为正数;阶码部分为10000010,则E=130,则e=E-127=3,则说明其向左移了3位,0001加上“整数”部分的1之后,为1.0001。则原二进制数为1000.1=十进制8.5,或R=1.0001*2^3=8.5

其中很多计算类似。可举一反三!

转载于:https://www.cnblogs.com/ivorfeng/archive/2013/04/04/2999220.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/274299.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

学习ui设计_如果您想学习UI设计,该怎么办

学习ui设计There is a question that is always asked when we want to learn something new.当我们想学习新东西时,总会问一个问题。 Where to start?从哪儿开始? This is also being my question when I want to learn UI design. In this article, …

Christmas

html5 game - Christmasloading......转载于:https://www.cnblogs.com/yorhom/archive/2013/04/05/3001116.html

30个WordPress Retina(iPad)自适应主题

原文地址:http://www.goodfav.com/zh/retina-ready-wordpress-themes-3556.html WordPress Retina定制主题进行了优化,支持Retina屏幕上的高品质和清晰的图像。如果你关心这个话题,又不知道这究竟是什么,那么请你继续阅读。 wordp…

Thinking in java第一章对象导论

这一章,做笔记感觉不是很好做。每个人又每个人对面向对象的理解。这里说一下书里的关键字,穿插一下自己的思想 面向对象的编程语言里面很流行的一句话,一切都是对象。面向对象的核心就是抽象,抽象的能力有大有小,是决定…

Android SlidingMenu插件的使用

1、在github上下载了源码后 不知道如何使用,在折腾了一个晚上后终于弄好了 下载地址 https://github.com/jfeinstein10/SlidingMenu 下载完后,解压,然后先import 其中的library ,然后把项目名改为SlidingMenu 2、然后再到http…

css 字体字体图标_CSS基础知识:了解字体

css 字体字体图标In this tutorial, we’ll be learning about working with fonts in CSS!在本教程中,我们将学习有关在CSS中使用字体的知识! The font property is a shorthand property which can combine a number of sub-properties in a single d…

openstack quantum搭建过程中一些有用的链接

OpenvSwitch的概念和流程: http://blog.wachang.net/2013/03/openvswitch-fullbook-2-workflow-1/ OpenvSwitch的vlan模式: http://openvswitch.org/support/config-cookbooks/vlan-configuration-cookbook/ OpenvSwitch问答: http://openvsw…

mysql下载哪一代版本好_潮一代更好的设计

mysql下载哪一代版本好I think we can all agree that quarantined life has been strange. And while most of the day is comprised of the monotony of domestic life, I’ve been surprised at how much of my time is dominated by technology.我认为我们都可以同意隔离的…

预约清单ui设计_持续交付质量设计所需的UI清单

预约清单ui设计重点 (Top highlight)Over the past few months, my design team at StreetEasy has started experimenting in adding a “design buddy” check-in to the final stages of the design process.在过去的几个月中,我在StreetEasy的设计团队已开始尝试…

黑书上的DP例题

pagesectionnotitlesubmit1131.5.1例题1括号序列POJ11411161.5.1例题2棋盘分割POJ11911171.5.1例题3决斗Sicily18221171.5.1例题4“舞蹈家”怀特先生ACM-ICPC Live Archive1191.5.1例题5积木游戏http://202.120.80.191/problem.php?problemid12441231.5.2例题1方块消除http://…

静态创意和动态创意_我在22岁时学到的关于创意指导的知识

静态创意和动态创意During my last semester at college, I took a course titled “Collaborative Workshop”. The entire course focused on how to best collaborate within a team setting. We were placed into groups of 4 or 5. These were our “creative director” …

vim7.1在windows下的编码设置[转]

在gvm配置文件中: (gvim安装目录下的_vimrc文件中) """""""""""""""""""""""""""""&…

绝对编码和增量编码_用户体验设计师应该学习编码吗? 绝对

绝对编码和增量编码Even though I was trained as a graphic designer, I’ve never limited myself to that field exclusively. My particular interest in how things work didn’t allow me to stand still and as a young kid, I was already pulling apart all my toys t…

两个ID

在itpub上注册了ID googlgoracle ,发过不少的求助帖子。 http://www.itpub.net/home.php?modspace&dothread&viewme 在CSDN 上ID:googlg,注册时间挺早的2008年,一直也没有弄过。 http://write.blog.csdn.net/postlist http://blog.csdn.net/goo…

完美主义怎么解决_相信我,你不要完美主义

完美主义怎么解决Perfectionism to UXers is like a badge of honour. We pride ourselves on the attention to detail and the drive to constantly push our work to the next level. When I asked some of my clients who share this sentiment about perfectionism, they …

MDK linker和debug的设置以及在RAM中调试

有误或者表述不清楚请指出,谢谢 硬件:TQ2440开发板、jlink V8 固件 软件:J-LINK ARM 4.08i、MDK4.20 先解释下MDK中三种linker之间的区别 设置集中在option linker选项卡 1.采用Target对话框中的ram和rom地址。采用此方式,…

FS_S5PC100 UBOOT-2011.12移植,支持DM9000

在uboot中已经支持了DM9000驱动代码在drivers/net/目录下的dm9000x.c dm9000x.h 修改include/configs/smdkc100.h 文件,注释掉SMC911X的支持,添加对DM9000的支持//#define CONFIG_SMC911X 1 /* we have a SMC9115 on-board *///#define…

为什么ui框架设计成单线程_评估UI设计的备忘单

为什么ui框架设计成单线程Whether you’re evaluating your design proposals or giving feedback to a colleague during a design critique or an informal conversation, you may find this actionable cheat sheet valuable. It’s quick to digest and its questions are …

css 菜单栏悬停_在CSS中构建悬停菜单

css 菜单栏悬停A good menu design is an important part of any website or web app UI. Using only modern HTML and CSS, all kinds of menu combinations can be created to handle whatever user interactions are necessary. In this article, we’ll take a look at how…

一级学科和二级学科_在多学科团队中工作的6个障碍(以及如何解决这些问题)

一级学科和二级学科In a team with different skillsets, one can be hopeful and idealistic about the outcome. The goal is to work as one team, put users first and create awesome experiences. Unfortunately, things don’t always go as planned.在一支具有不同技能…