-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20_bit_of_float_and_double.c
79 lines (76 loc) · 1.48 KB
/
20_bit_of_float_and_double.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Author: Girish Gaude
* Date: 20/Jan/2020
* Desciption: Program to Print bits of float & double.
* Input: Enter Float or Double number
* Output: Display IEEE converted output
*/
#include<stdio.h> //header file
void my_ieee(float num, int opt) //Function
{
void *p = # //Declare variable
int out;
if(opt == 1) //Check option
{
for(int i = 33; i>=0; i--) //Float
{
if( i == 23 || i == 32 ) //Put space
printf(" ");
else
{
out = (*(int*)p >> i) & 1; //Print one
printf("%d",out);
}
}
printf("\n");
}
else //For double
{
for(int i = 65; i>0; i--) //Put space
{
if( i == 64 || i == 53 )
printf(" ");
else
{
out = (*(long int*)p >> i) & 1; //Print onces
printf("%d",out);
}
}
}
}
int main()
{
char ch;
do
{
int opt;
printf("Please Select the type \n\t1. Float\n\t2. Double\n");
scanf("%d", &opt); //ask for option
switch(opt)
{
case 1: //For Float value
{
float num;
printf("Enter the Float number\n");
scanf("%f", &num);
my_ieee(num, opt); //Call function
break;
}
case 2:
{
double num1; //For double
printf("Enter the Double number\n");
scanf("%lf", &num1);
my_ieee(num1, opt); //Call Function
break;
}
default: //Error if no proper input
printf("Error : Enter Valid Input\n");
break;
}
printf("\nDo you want to continue.\n");
getchar();
scanf("%c", &ch);
}while( ch == 'y' ); //continue again
return 0;
}