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

Write two individual C programs for question 1 and 2. binary number defined as:

ID: 3590002 • Letter: W

Question

Write two individual C programs for question 1 and 2.

binary number defined as: int binNum[8];

1. Defining bAnd, bin1, and bin2 as binary numbers as above, write the void function

void binaryAnd(int bAnd[],
               const int bin1[], const int bin2[])

to compute bAnd as the AND of the two binary numbers bin1 and bin2. Do not output the binary number in the function. Test your function with 7,8 and 32, 255.

2. Write the void function for Problem 2 above renamed as binaryOr() using the OR operation.

Explanation / Answer

Hi,

I have written sample code for AND operation-

#include <stdio.h>
void binaryAnd(int bAnd[], const int bin1[], const int bin2[]);
int main()
{
int a[]={1,0,1,1,1,0,1,1};
int b[]={1,0,1,1,1,0,1,0};
int m = (sizeof(a) / sizeof(int));
int c[m];
binaryAnd(c,a,b);
return 0;
}
void binaryAnd(int bAnd[], const int bin1[], const int bin2[]) {
int i,k;
int j=0;
int n = sizeof(bAnd) /sizeof(int);
printf("%d",sizeof(bAnd) );
for(i=0;i<8;i++){
if(bin1[i]==1&&bin2[i]==0)
{
bAnd[j]=0;
j++;
}
if(bin1[i]==0&&bin2[i]==0)
{
bAnd[j]=0;
j++;
}
if(bin1[i]==0&&bin2[i]==1)
{
bAnd[j]=0;
j++;
}
if(bin1[i]==1&&bin2[i]==1)
{
bAnd[j]=1;
j++;
}
}
for(k=0;k<8;k++)
{
printf("%d",bAnd[k]);
}
  
}