i have this project in c programming language
1.I have to input a float number which after calculating returns me a 32-bit
note stored in a 32 bit registry .
it has been put to my attention that the --for (int i=0;i>=1;i--) -- part of the code is not being caried out , so can anyone help me fix this problem
Code:
#include<stdio.h>
int main(){
char binbroj[32];
int predznak = 1;
int pot=0;
float realniBroj,frac;
int E;
printf("Unesi realni broj");
scanf("%f",&realniBroj);
if (realniBroj < 0)
{
predznak = -1;
frac = realniBroj * predznak;
binbroj[0] ='1';
}
if (frac < 1 )
{
while (frac < 1)
{
frac *= 2.0;
pot--;
}
}
else {
while (frac > 2)
{
frac /= 2.0;
pot++;
}
}
E = pot * 127 ;
for (int i=0;i>=1;i--)
{
if (E % 2 == 0)
binbroj = '0';
else
binbroj ='1';
E /= 2;
}
frac -= 1;
for (i=9;i<=31;i++){
frac *= 2.0;
if (frac >=1) {
binbroj = '1';
frac -= 1.0;
} else binbroj ='0';
}
printf("float number %f in registry has a binary note \n",realniBroj);
for(i=0;i<32;i++)
{
if(i==1) printf (" ");
if(i==9) printf (" ");
printf("%c",binbroj);
}
}
1.I have to input a float number which after calculating returns me a 32-bit
note stored in a 32 bit registry .
it has been put to my attention that the --for (int i=0;i>=1;i--) -- part of the code is not being caried out , so can anyone help me fix this problem
Code:
#include<stdio.h>
int main(){
char binbroj[32];
int predznak = 1;
int pot=0;
float realniBroj,frac;
int E;
printf("Unesi realni broj");
scanf("%f",&realniBroj);
if (realniBroj < 0)
{
predznak = -1;
frac = realniBroj * predznak;
binbroj[0] ='1';
}
if (frac < 1 )
{
while (frac < 1)
{
frac *= 2.0;
pot--;
}
}
else {
while (frac > 2)
{
frac /= 2.0;
pot++;
}
}
E = pot * 127 ;
for (int i=0;i>=1;i--)
{
if (E % 2 == 0)
binbroj = '0';
else
binbroj ='1';
E /= 2;
}
frac -= 1;
for (i=9;i<=31;i++){
frac *= 2.0;
if (frac >=1) {
binbroj = '1';
frac -= 1.0;
} else binbroj ='0';
}
printf("float number %f in registry has a binary note \n",realniBroj);
for(i=0;i<32;i++)
{
if(i==1) printf (" ");
if(i==9) printf (" ");
printf("%c",binbroj);
}
}