Question: I am writing a function that will remove trailing zeros from a number so if input is -3342.808768 output will be -1.10100001110110011110001E11 if input is

I am writing a function that will remove trailing zeros from a number so if input is

-3342.808768 output will be 
-1.10100001110110011110001E11 

if input is 0 output will be 0E0

and if input is

-2280.294101 then output will be -1.00011101000010010110101E11 

I know I have an error in the function that takes out the trailing zeros. And I think I have an error in the bitwise opperators too. Can someone help me with this? Thanks!

#include #include #include using namespace std; void removeTrailZero(int array[]) { //this function goes though the string and removes trailing zeros int i=0; for (i = 22; array[i]==0; i--){ //printf("%d",i); } //printf("%d",i); //5318.010437 for (int x=1;x<=i; x++){ printf("%d",array[x]); //-2280.294101 } return; } int main() { printf("Please enter a float: "); float floatNum; scanf("%f",&floatNum); int array[23]; unsigned int num = *((unsigned int*)&floatNum); int s = 0; s = num >> 31; if(s == 1) printf("-1."); else printf("1."); int exp = (num >> 23) & (0xFF); exp = exp - 127; int x = 1; for(int i = 22; i>0; i--){ int z = ((num>>i)&0x1); array[x]=z; x++; //printf("%d",z); } removeTrailZero(array); printf("E%d",exp); } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!