当前位置:网站首页>How to store floating point data in memory
How to store floating point data in memory
2022-07-28 06:46:00 【JuLiJuLi.】
(5) For index E There are also rules ,E If it is an unsigned integer , hypothesis E by 8 position , Its value range is 0~255; If E by 11 position , Its value range is 0~2047. however , We know , In scientific counting E Yes, you can Now negative , the IEEE 754 in Regulations , In memory E The true value of must be added with an intermediate number ,
about 8 Bit E, This middle number yes 127; about 11 Bit E, In the middle The number is 1023.
give an example :2^10 Of E yes 10, So save it as 32 When floating-point numbers are in place , must 10+127=137, namely 10001001.
(6). When index E There are also the following three situations when fetching from memory
1. When index E Incomplete 0 Or not all 1 when
When converting an integer to a floating-point type, the exponent E The real value of is :E Calculated value -127( perhaps 1023)
give an example :0.5 The binary form of is 0.1, Since it is stipulated that the positive part must be 1, Move the decimal point right 1 position , Then for 1.0*2^(-1), Index E by -1+127, Expressed as 01111110, And the mantissa 1.0 Remove the integer part and make it 0, Make up the remaining 0~23 position :
#include<stdio.h>
int main()
{
int li = 9;
float* flag = (float*)&li;
printf("n The value of is :%d\n", li); //9
printf("flag The value of is :%f\n", *flag);//0.000000
// First, reshape 9 Convert to floating point , obtain 0 00000000 00000000000000000001001 Split ,
// You can get the first sign bit S=0, The next eight digit index E=00000000, The remaining 23 Significant digits of bits M=000 0000 0000 0000 0000 1001
//V=(-1)^0*0.00000000000000000001001×2^(-126)=1.001×2^(-146)
//S=0,E=00000000 Namely -126,M=000 0000 0000 0000 0000 1001
//V Is a close to 0 Positive number of , So decimal decimal means :0.00000000
*flag = 9.0;
printf("n The value of is :%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 This 32 The binary number of bits , Restore to decimal , Namely 1091567616
printf("flag The value of is :%f\n", *flag);//9.000000
return 0;
}边栏推荐
- OJ 1089 Spring Festival travel
- SSAO by computer shader (III)
- Execjs call
- Everything you don't know about time complexity is here
- OJ 1129 fraction matrix
- Two dimensional array practice: spiral matrix
- NFT data storage blind box + mode system development
- Redis cache design and performance optimization
- JS逆向100题——第1题
- explain详解
猜你喜欢

AQS之ReentrantLock源码解析

mongo ssl 配置实战
![[PTA----输出全排列]](/img/66/d1699cd55fa5ff4a55e3e150d02c1b.png)
[PTA----输出全排列]

Graphic pipeline foundation (part outside)

用c语言实现三子棋小游戏

AQS之countDownLatch源码分析

Optimization ideas from ordinary query commodities to highly concurrent query commodities
![[pta-- use queues to solve the problem of monkeys choosing kings]](/img/54/94359fb3557ac07f7786ecf61a5409.png)
[pta-- use queues to solve the problem of monkeys choosing kings]
![[C note] data type and storage](/img/3d/6b7a848dff5a8c0ccd0a54c19bce46.png)
[C note] data type and storage

Leetcode 刷题日记 剑指 Offer II 053. 二叉搜索树中的中序后继
随机推荐
About the collation of shader keyword
JS逆向100题——第1题
Pyppeteer is recognized to bypass detection
yapi漏洞挂马程序chongfu.sh处理
【二叉树基础知识】
RayMarching实现体积光渲染
OJ 1018 counting game
OJ 1131 美丽数
OJ 1020 minimum palindromes
[哈希表基础知识]
Dynamic programming -- simple question type of climbing stairs
OJ 1505 fuse
OJ 1020 最小的回文数
AQS之ReentrantLock源码解析
Mongodb quick start
OJ 1045 反转然后相加
2022-07-17 Damon database installation
OJ 1129 分数矩阵
Leetcode 刷题日记 剑指 Offer II 048. 序列化与反序列化二叉树
Valgrind tool