Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am writing a program that converts integers to 32 bit binary array then conver

ID: 3815900 • Letter: I

Question

I am writing a program that converts integers to 32 bit binary array then converts the binary array into a alphabetical system where 1 = 000 0000 0000 0000 0000 00000001 = a,

000 0000 0000 0000 0000 00000010 = b

000 0000 0000 0000 0000 00000100 = c

I completed everything except for for the last part where if the most RHS bit is a 1, the system changes to uppercase letters so 67108866 = 100 0000 0000 0000 0000 00000010 = B and 100 0000 0000 0000 0000 0000

0001 = A. Can someone help me with the Upper case? I can't get the ascII code right for the capital letters.

Thanks!   

#include<stdio.h>

#include<string.h>

#include <math.h>

#include <stdlib.h>

#include <stdio.h>

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(i=0;i<=30;i++)

{

if (array[i]==1 && array[31]==0)

temp= i+97;

}

printf("%c",(char)temp);

}

}

printf(" ");

return 0;

}

int main (int argc, char *argv[])

{

int count;

printf ("This program was called with "%s". ",argv[0]);

to_Binary(argv+1,argc-1);

  

return 0;

}

Explanation / Answer

#include<stdio.h>
#include<string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
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(i=0;i<=30;i++)
{
if (array[i]==1 && array[31]==0)
temp= i+97;

}

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;

printf ("This program was called with "%s". ",argv[0]);


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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote