IEEE - 754 - 找到signbit,指数,压裂,标准化等 [英] IEEE - 754 - find signbit, exponent, frac, normalized, etc

查看:135
本文介绍了IEEE - 754 - 找到signbit,指数,压裂,标准化等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以一个8位十六进制数字作为一个IEEE 754位浮点数
我想打印有关数字(signbit,expbits,fractbits,规范化的信息,
非规范化,无穷大,零,NAN)浮点应该是单一的。

I am taking in a 8 digit hexadecimal number as an IEEE 754 bit floating point number and i want to print information about that number( signbit, expbits, fractbits, normalized, denormalized, infinity, zero, NAN) floating point should be a single.

我对位移位读了,我觉得这就是我想怎么办呢?不过,我不是100%确定。据我所知,符号位在数字的最左边的位置找到。其指示正或负。多少钱,我转向它找到每个?做我还是想继续转向它来查找每一个?有人能解释如何,我发现每一个?

I read up on bit shifting, and i think this is how i am suppose to do it?. however, i am not 100% sure. I understand that the sign bit is found in the left most position of the number. which indicates positive or negative. How much do i shift it to find each? do i just keep shifting it to find each one? Can someone explain how i am to find each one?

,我会转移1找到signbit?
我会用8移来获得的指数?
我会用23移来获取压裂?

would i shift by 1 to find the signbit? would i shift by 8 to get the exponent? would i shift by 23 to get the frac?

signbit应为零

signbit should be zero

expbits应该是128

expbits should be 128

fracbits应00000000
我想......

fracbits should be 0x00000000 I think...

如果让我怎么测试我后移?

if so how do i test it after i shift?

这是我迄今为止

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{

    short wordOrder = 0x0100;

int HexNumber;

printf("Hex IEEE - 754\n");



    if(wordOrder == 0x0100)
    {
    printf("\nbyte order: big-endian\n");
    }
    else
    {
    printf("byte order: little-endian\n");
    }

printf("\n>");
scanf("%x", &HexNumber);
printf("\n%#x",HexNumber);




return 0;
    }

我的输入(scanf函数)
对我多么希望它..

my input(scanf) on how i want it..

>40000000
0x40000000

这就是它做的。

推荐答案

对于单个precision数最高位为标志,接下来的8位是指数,其余23位是尾数。所以......

For a single precision number the high bit is the sign, the next 8 bits are the exponent and the remaining 23 bits are the mantissa. So...

bool negative = !!(HexNumber & 0x80000000);
int exponent = (HexNumber & 0x7f800000) >> 23;
int mantissa = (HexNumber & 0x007FFFFF);

如果该指数是255,数是+ - 无穷或NaN取决于尾数是否为零(0表示无穷大)。
如果该指数是零,那么醚数为+ - 零(如果尾数是零)或尾数是实际非标准化分数值

If the exponent is 255, the number is either +- infinity or NaN depending on whether the mantissa is zero (0 means infinity). If the exponent is zero then ether the number is +- zero (if the mantissa is zero) or the mantissa is the actual unnormalized fractional value.

如果该指数是别的,上有部分的顶部,使得它的24位的隐藏一比特。在这种情况下,实际的指数可以通过从指数中减去127被计算,使得它的范围是从-127到+127,两个幂指数

If the exponent is anything else, there is a hidden one bit on the top of the fraction, making it 24 bits. In this case, the actual exponent can be calculated by subtracting 127 from the exponent so that it is in the range -127 to +127, the power of two exponent.

这篇关于IEEE - 754 - 找到signbit,指数,压裂,标准化等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆