float 内存如何存储的

来源:互联网 发布:人工智能 剩余价值 编辑:程序博客网 时间:2024/05/13 12:26

float 内存如何存储的

类型

存储位数

总位数

偏移值
(offset)

数符(S)

阶码(E)

尾数(M)

短实数(float) 

   1 

   8

  23

   32

127

长实数(double)

   1

   11

  52

   64

 1023

 

N (10) = 123.456,

换算成二进制表示:

N (2) = 1111011. 01110100101111001

= 1. 11101101110100101111001(...) * 2^6

   那么E– 127 = 6;  E = 127 + 6 = 133(10) = 10000101(2)

M = 111 0110 1110 1001 0111 1001(省略了最高数字位1,23bit)

   组合起来就是:

S         E                       M

0       10000101      1110110 1110 1001 0111 1001

   4bit一间隔:

0100   0010   1111   0110  1110   1001   0111   1001

 4         2          F           6         E          9         7         9 

// floatMem.cpp : Defines the entry point for the console application.//#include "stdafx.h"typedef union{float fa;unsigned char arry[4];}MyUnion;int main(int argc, char* argv[]){MyUnion var;var.fa=123.456f;printf("%x,%x,%x,%x\n",var.arry[0],var.arry[1],var.arry[2],var.arry[3]);return 0;}/*79,e9,f6,42Press any key to continue*/


原创粉丝点击