gpt4 book ai didi

C : how is double number (e.克。 123.45) 存储在 float 变量或 double 变量或 long double 变量中?

转载 作者:太空狗 更新时间:2023-10-29 15:53:19 25 4
gpt4 key购买 nike

#include <stdio.h>

int main () {
float a = 123.0;

unsigned char ch, *cp;
ch = 0xff;

cp = (unsigned char *) &a;
printf ("%02x", ch&(*(cp+3)));
printf ("%02x", ch&(*(cp+2)));
printf ("%02x", ch&(*(cp+1)));
printf ("%02x\n", ch&(*(cp+0)));

/*I have written this program to see binary representation, but I can not understand the output, the binary representation?
}

最佳答案

参见维基百科:http://en.wikipedia.org/wiki/Single_precision_floating-point_format ,它将单精度浮点(典型的 C float,但取决于编译器)描述为 1 位符号、8 位偏置指数和 24 位尾数(存储 23 位) .

以你的例子为例:

123.0 = 42f60000hex = 0 10000101 11101100000000000000000bin
1-bit sign = 0 (indicating positive number)
8-bit biased exponent = 10000101bin = 133dec - 127dec = 6dec
23-bit mantissa = 11101100000000000000000bin = 1.111011bin (note implied leading 1)

Converting 1.111011bin x 26dec = 1111011.0bin = 123.0dec

关于C : how is double number (e.克。 123.45) 存储在 float 变量或 double 变量或 long double 变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6535343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com