搜索
bottom↓
回复: 14

帮忙!为什么浮点变量值-12.5的十进制为:0xc1480000?(老师布置作业要我们解释!)

[复制链接]

出0入0汤圆

发表于 2009-10-8 11:04:38 | 显示全部楼层 |阅读模式
为什么浮点变量值-12.5的十进制为:0xc1480000?(老师布置作业要我们解释!)

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2009-10-8 11:10:26 | 显示全部楼层
刷新下!

出0入0汤圆

 楼主| 发表于 2009-10-8 11:18:58 | 显示全部楼层
为什么浮点变量值-12.5的十进制为:0xc1480000?具体过程怎么来的?

出0入0汤圆

发表于 2009-10-8 11:36:53 | 显示全部楼层
0x开头可不是什么十进制表示方法...

出0入0汤圆

发表于 2009-10-8 11:43:32 | 显示全部楼层
“为什么浮点变量值-12.5的十进制为:0xc1480000”
十进制是否应该改为“十六进制”?

出0入0汤圆

发表于 2009-10-8 11:52:51 | 显示全部楼层
什么格式的浮点?

出0入0汤圆

 楼主| 发表于 2009-10-8 13:26:07 | 显示全部楼层
为什么浮点变量值-12.5的十进制为:0xc1480000?具体过程怎么来的?

出0入0汤圆

 楼主| 发表于 2009-10-8 13:27:28 | 显示全部楼层
为什么浮点变量值-12.5为:0xc1480000?具体过程怎么来的?

出0入0汤圆

发表于 2009-10-8 13:41:07 | 显示全部楼层
看图就清楚

(原文件名:float.JPG)

出0入0汤圆

发表于 2009-10-8 14:54:45 | 显示全部楼层
float Scalars

Scalars of type float are stored using four bytes (32-bits). The format used follows the IEEE-754 standard and is stored little endian or LSB first.

A floating-point number is expressed as the product of two parts: the mantissa and a power of two. For example:

±mantissa × 2exponent

The mantissa represents the actual binary digits of the floating-point number.

The power of two is represented by the exponent. The stored form of the exponent is an 8-bit value from 0 to 255. The actual value of the exponent is calculated by subtracting 127 from the stored value (0 to 255) giving a range of –127 to +128.

The mantissa is a 24-bit value (representing about seven decimal digits) whose most significant bit (MSB) is always 1 and is, therefore, not stored. There is also a sign bit that indicates whether the floating-point number is positive or negative.

Floating-point numbers are stored on word boundaries in the following format:

         Address+0 Address+1 Address+2 Address+3
Contents MMMM MMMM MMMM MMMM EMMM MMMM SEEE EEEE


Where

S represents the sign bit where 1 is negative and 0 is positive.
E is the exponent with an offset of 127.
M is the 24-bit mantissa (stored in 23 bits).

Zero is a special value denoted with an exponent field of 0 and a mantissa of 0.

Using the above format, the floating-point number -12.5 is stored as a hexadecimal value of 0xC1480000. In memory, this value appears as follows:

  Address+0 Address+1 Address+2 Address+3
Contents 0x00 0x00 0x48 0xC1

It is fairly simple to convert floating-point numbers to and from their hexadecimal storage equivalents. The following example demonstrates how this is done for the value -12.5 shown above.

The floating-point storage representation is not an intuitive format. To convert this to a floating-point number, the bits must be separated as specified in the floating-point number storage format table shown above. For example:

  Address+0 Address+1 Address+2 Address+3
Format MMMMMMMM MMMMMMMM EMMMMMMM SEEEEEEE
Binary 00000000 00000000 01001000 11000001
Hex 00 00 48 C1

From this illustration, you can determine the following:

The sign bit is 1, indicating a negative number.
The exponent value is 10000010 binary or 130 decimal. Subtracting 127 from 130 leaves 3, which is the actual exponent.
The mantissa appears as the following binary number:
10010000000000000000000
There is an understood binary point at the left of the mantissa that is always preceded by a 1. This digit is omitted from the stored form of the floating-point number. Adding 1 and the binary point to the beginning of the mantissa gives the following value:

1.10010000000000000000000
To adjust the mantissa for the exponent, move the decimal point to the left for negative exponent values or right for positive exponent values. Since the exponent is three, the mantissa is adjusted as follows:

1100.10000000000000000000
The result is a binary floating-point number. Binary digits to the left of the decimal point represent the power of two corresponding to their position. For example, 1100 represents (1 × 23) + (1 × 22) + (0 × 21) + (0 × 20), which is 12.

Binary digits to the right of the decimal point also represent the power of two corresponding to their position. However, the powers are negative. For example, .100... represents (1 × 2-1) + (0 × 2-2) + (0 × 2-3) + ... which equals .5.

The sum of these values is 12.5. Because the sign bit was set, this number should be negative.

So, the hexadecimal value 0xC1480000 is -12.5.

Copyright (c) Keil Software, Inc. and Keil Elektronik GmbH. All rights reserved.

看看你的keil中索引float,上面是完整的拷贝。现在的老师也够懒的,出的题居然从keil里找,呵呵。你自己翻译吧。

出0入0汤圆

 楼主| 发表于 2009-10-8 17:06:35 | 显示全部楼层
还是不懂!明天就要教了!再刷新一下!希望能有简显易动的解释!!

出0入0汤圆

发表于 2009-10-8 17:07:54 | 显示全部楼层
明天听你的老师怎么解释吧.

出0入0汤圆

 楼主| 发表于 2009-10-8 17:08:10 | 显示全部楼层
上面的图不懂!
洋文更是不会!

出0入0汤圆

发表于 2009-10-8 17:08:50 | 显示全部楼层
楼主还是google一下吧,几分钟看完就懂了,论坛上讲清楚还不如自己看方便呢

出0入0汤圆

发表于 2009-10-8 17:10:32 | 显示全部楼层
给两个链接,看看能帮上忙不

http://www.google.cn/search?hl=zh-CN&source=hp&q=ieee754%E6%B5%AE%E7%82%B9%E6%95%B0&btnG=Google+%E6%90%9C%E7%B4%A2&aq=2&oq=IEEE754

http://blog.csdn.net/on_road/archive/2008/01/05/2027177.aspx
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-17 11:26

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表