티스토리 뷰

기억하자정보/기타

IEEE 754 소스

LANIAN 2006. 9. 26. 16:51

#include <stdio.h>
#include <stdlib.h>
#define ARRAY_SIZE 8

int main()
{
double fnum;
char *apcNumber[ARRAY_SIZE];
int iIndex=0;
int count=0;
int bin[64]={0};
int i,j=1,sum=0,toggle=1;
int dResult=0, dTemp=1;
unsigned long xsum[2]={0,0};

while(1)
{

 printf("IEEE754 64bit(double type) Test...\n");
 printf("input value : ");
 scanf("%lf",&fnum);

 for(iIndex=0; iIndex<ARRAY_SIZE; iIndex++)
 {
  apcNumber[iIndex] = ((char *)(&fnum))+(ARRAY_SIZE-iIndex)-1;
 }
 for(iIndex=0; iIndex<ARRAY_SIZE; iIndex++)
 {
  for(i=1; i<=8; i++)
  {
   if( (*(apcNumber[iIndex]) & (0x01 << (8 - i))) != 0)
   {
    bin[count] = 1;
    count++;
   }
   else
   {
    bin[count] = 0;
    count++;
   }
  }
 }
 printf("\n");
 printf("DEC : %lf\n",fnum);

 for(count=0;count<64;count++)
 {
   xsum[count/32]*=2;
   xsum[count/32]+=(bin[count]);
 }
 printf("HEX : %x%x \n",xsum[0],xsum[1]);
 printf("BIN : S EEEEEEEEEEE
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMM\n");
 printf("      ");
 for(count=0;count<64;count++)
 {
  if(count==1 || count==12)
   printf(" ");
  printf("%d",bin[count]);
 }
 printf("\n");
 printf("Sign : %d\n",bin[0]);

 while(bin[j]==1 || bin[j]==0)
 {
  if(j==12)break;

  dResult*=2;
  dResult+=(bin[j]-0);

  j++;
 }

 printf("Exponent : %d\n",dResult);
}
return 0;
}

댓글
안내
궁금한 점을 댓글로 남겨주시면 답변해 드립니다.