#include <stdio.h>
#include <string.h>
int main()
{
while(1)
{
int n = 0;
int nBit[32] = {0};
union IntFloat{
int IntegerNum;
float floatNum;
};
typedef union IntFloat Unf;
Unf num;
char cNum[32] = {'\0'};
printf("enter a number\n");
scanf("%s",&cNum);
if(NULL == strchr(cNum,'.')){
printf("enter number is int type\n");
sscanf(cNum,"%d",&n);
}
else{
printf("enter number is float type\n");
sscanf(cNum,"%f",&num.floatNum);
n = num.IntegerNum;
}
printf("hex = %x\n",n);
int temp = 0x01;
printf("bit stream\n");
int nCount = 0;
while(n)
{
nBit[nCount] = n&temp;
nCount++;
n>>=1;
}
int nTol = nCount;
while(nCount--)
{
printf("%d\t",nBit[nCount]);//backward order output
if((nTol - nCount)%4 == 0)
printf("\n");
}
printf("\n");
int state = 0;
printf("1.continue 0.quit");
scanf("%d",&state);
if(!state)
break;
}
return 0;
}