Question: I am writing a program that converts a number to to binary. I am having a problem with the 32 digit. instead of converting the

I am writing a program that converts a number to to binary. I am having a problem with the 32 digit. instead of converting the number 67108865 to 100 0000 0000 0000 0000 00000001 and 67108866 to 100 0000 0000 0000 0000 00000010.the MSB doesn't get flipped. Can someone help me out?

In the end, 100 0000 0000 0000 0000 00000001 wil print out A and 100 0000 0000 0000 0000 00000010. prints out B.

Thanks!

#include #include #include #include #include using namespace std; int to_Binary(char *argv[],int number_Of_Nums){ { int count =0; for (count = 0; count < number_Of_Nums; count++) {

int deci = atoi(argv[count]); int array[32];

int n = 0;

for(n=31; n>=0; n--) { if(deci>=pow(2,n)){ array[n]=1; deci = deci-pow(2,n); } else array[n] = 0; } //printf(" ");

//next convert binary to letter value int temp=0; int i;

for( n = 31; n >=0; n-- ){ printf( "%d", array[ n ] ); }

for(i=0;i<=30;i++) { if (array[i]==1 && array[31]==0) temp= i+97; else if(array[i]==1 && array[31]==1) temp= i; }

printf("%c",(char)temp); // this line prints the ASCII value of charcters printf("ASCII value of %c = %d",(char)temp, (char)temp);

} }

printf(" "); return 0; }

int main (int argc, char *argv[]) { int count;

to_Binary(argv+1,argc-1); return 0; }

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!