当前位置:网站首页>浮点型数据在内存中如何存储
浮点型数据在内存中如何存储
2022-07-28 05:26:00 【JuLiJuLi.】
(5)对于指数E也有规定,E如果是一个无符号整数,假设E为8位,它的取值范围为0~255;如果E为11位,它的取值范围为0~2047。但是,我们知道,科学计数法中的E是可以出现负数的,所IEEE 754中规定,存入内存时E的真实值必须再加上一个中间数,
对于8位的E,这个中间数是127;对于11位的E,这个中间数是1023。
举例:2^10的E是10,所以保存成32位浮点数时,必须10+127=137,即10001001。
(6).当指数E从内存中取出时也有以下三种情况
1.当指数E不为全0或者不为全1时
整型转换为浮点型时指数E的真实值是:E的计算值-127(或者1023)
举例:0.5的二进制形式是0.1,由于规定正数部分必须为1,小数点右移1位,则为 1.0*2^(-1),指数E为-1+127,表示为01111110,而尾数1.0去掉整数部分为0,补齐剩余0~23位:
#include<stdio.h>
int main()
{
int li = 9;
float* flag = (float*)&li;
printf("n的值是:%d\n", li); //9
printf("flag的值是:%f\n", *flag);//0.000000
//首先将整形9转换为浮点型,得到0 00000000 00000000000000000001001拆分,
//可以得到第一位符号位S=0,后面接着的八位的指数E=00000000,剩余23位的有效位数字M=000 0000 0000 0000 0000 1001
//V=(-1)^0*0.00000000000000000001001×2^(-126)=1.001×2^(-146)
//S=0,E=00000000就是-126,M=000 0000 0000 0000 0000 1001
//V是一个接近于0的正数,所以十进制小数表示是:0.00000000
*flag = 9.0;
printf("n的值是:%d\n", li); //1091567616
//V=(-1)^0*1.001*2^3
//S=0,E=3+127,M=1.001
//0 10000010 001 0000 0000 0000 0000 0000
//V=1091567616 这个32位的二进制数,还原成十进制,就是 1091567616
printf("flag的值是:%f\n", *flag);//9.000000
return 0;
}边栏推荐
- 自定义组件--父子组件之间的通信
- Vs code basic configuration and beautification
- [server usage record] log in to the remote server through the springboard machine and transfer files
- QT batch operation control and set signal slot
- Explain the installation of MSDN 2015 and precautions
- Pytorch learning notes 3 - datasets & dataloaders & transforms
- NPM yarn related operations
- 开放式耳机推荐哪款最好、性价比最高的开放式耳机
- Pycharm2019 set editor theme and default code
- Ship detection in SAR image based on yolov5
猜你喜欢

小程序navigator无法跳转(debug)

2022-06-07 六.日志实现

Get the current directory in QT

Five categories of IP addresses

Solve the problem that the memory occupation is higher than that of the application process

2022-05-24 SpEL使用

Systemmediasize startup option added in esxi 7.0 update 1C

多个ics日历合并成单个ics日历

I heard that you are also practicing when I interviewed several junior interns.

小程序创建组件
随机推荐
自定义组件--数据监听器
ubuntu mysql 设置远程访问权限
Perl introductory learning (VIII) subroutine
Get the current directory in QT
qt中获取当前目录
MATLAB signal processing
如何模拟实现strcpy库函数
VI and VIM commands
刷题记录----反转链表(反转整个链表)
qt自定义滑动按钮(美观且使用方便)
藏宝计划TPC系统开发Dapp搭建
Esxi on ARM v1.2 (updated in November 2020)
Monitor the CPU temperature of raspberry pie 4B installed with esxi on ARM
根据IP地址和子网掩码求主机所在的网络地址和广播地址
Five categories of IP addresses
【学习笔记】链表操作
error: redefinition of ‘xxx‘
scrapy 定时执行
Hugging face 的问题记录 I
2022-06-07 六.日志实现