轉載--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.pswp.cn/news/274299.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274299.shtml
英文地址,請注明出處:http://en.pswp.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.在一支具有不同技能…