IEEE - 754 - 找到signbit,exponent,frac,normalized等 [英] IEEE - 754 - find signbit, exponent, frac, normalized, etc

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

问题描述

我收到一个8位十六进制数字作为IEEE 754位浮点数
,我想打印关于该数字的信息(signbit,expbits,fractbits,normalized,
denormalized,infinity,零,NAN)浮点应该是一个单一的。



我读了比特移位,我想这是我怎么想。然而,我不是100%肯定。我知道符号位是在号码的最左边的位置。表示正或负。我转移多少来找到每个?我只是继续移位它找到每一个?有人可以解释一下我是如何找到每一个?



我会换一个找到signbit吗?
我会移动8来获得指数?



signbit应该为零



expbits应该be 128



fracbits应该是0x00000000
我认为...



 <$ c $ 

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

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

short wordOrder = 0x0100;

int HexNumber;

printf(Hex IEEE - 754 \\\
);



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

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




return 0;
}

我的输入(scanf)

 > 40000000 
0x40000000

解决方案

对于单精度数字,高位是符号,接下来的8位是指数,剩余的23位是尾数。所以...

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

如果指数为255,则数字为+ - 无穷大或NaN,取决于尾数是零(0表示无穷大)。
如果指数为零,那么ether的数字为+ - 零(如果尾数为零),或尾数是实际未规范化的小数值。



指数是任何其他的,在分数的顶部有一个隐藏的一位,使其为24位。在这种情况下,实际指数可以通过从指数中减去127来计算,使得它在-127至+127的范围内,即两个指数的幂。


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.

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?

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 should be zero

expbits should be 128

fracbits should be 0x00000000 I think...

if so how do i test it after i shift?

this is what i have so far

#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;
    }

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

>40000000
0x40000000

which is what its doing..

解决方案

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);

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.

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,exponent,frac,normalized等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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