boj problem 1325 一次ac~~哈哈 第一次~~

Description
In IEEE 754-1985 standard, 32-bit single precision floating point number is stored as follows.
The highest bit is the sign bit, and following 8-bit is the exponent field, and 23-bit for fraction part:
s eeeeeeee mmmmmmmmmmmmmmmmmmmmmmm
The floating number has value v:
v= (-1)^S * 2^(E-127) * F
where S is the binary value of s.
Exponent E is an unsigned integer eeeeeeee (based 2)
Fraction F is fraction which formatted 1.mmmmmmmmmmmmmmmmmmmmmmm (based 2)

For example, consider the following 32-bit single precision floating point number:
1 10000001 01000000000000000000000

The sign bit is '1', thus the floating point number is negative.The exponent field is 129, making the exponent E=129-127=2.
The fraction part is .01(based 2)=.25(based 10), making the fraction F=1.01(based 2)=1.25(based 10). Thus, this bit pattern represents the number -1.25×2^2(based 10)= -5(based 10).

See more at http://en.wikipedia.org/wiki/IEEE_754


Input
Each line contains a string of 32 consecutive character, and only '0' or '1' will appear in the string.
It is guaranteed that no floating number in the input is greater than 10000.00 or smaller than 0.001 by its absolute value.


Output
For each line of the input, output a line containing the floating number to two decimal places.


Sample Input

11000000101000000000000000000000
01000001011000000000000000000000
01000000110001101000011100101011


Sample Output

-5.00
14.00
6.20


Source
champ

 

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
 
  char a[32];
  while(cin>>a)
  {
 int i,j,e=1,t=0;
    float n=0,k=1;
    for(i=1;i<9;i++)
 {
   t=t*2+(char(a[i])-48);
 }
 t=t-127;
 for(i=0;i<t;i++)
  e=e*2;

    for(i=9;i<32;i++)
 {
   k=k/2;
   if(a[i]=='1')
    n=n+k;
  
 }
 n=1+n;
 n=n*e;
 if(a[0]=='0')
  printf("%.2f/n",n);
 if(a[0]=='1')
  printf("-%.2f/n",n);

  }
  return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值