Defining a binary number as Program 1, write the function int binToDec(const int bin[]) to convert an eight-bit unsigned binary number to a nonnegative decimal integer. Do not output the decimal integer in the function. Test your function with interactive input. Defining bAnd, bin1, and bin2 as binary numbers as in Program 1 above, write the void function void binaryAnd(int bAnd[], const int bin1[], const int bin2[]) to compute bAnd as the logical AND of the two binary numbers bin1 and bin2. Do not output the binary number in the function. Test your function with interactive input.
Defining a binary number as Program 1, write the function
int binToDec(const int bin[]) to convert an eight-bit unsigned binary number to a nonnegative decimal integer. Do not output the decimal integer in the function. Test your function with interactive input.
Defining bAnd, bin1, and bin2 as binary numbers as in Program 1 above, write the void function
void binaryAnd(int bAnd[], const int bin1[], const int bin2[])
to compute bAnd as the logical AND of the two binary numbers bin1 and bin2. Do not output the binary number in the function. Test your function with interactive input.
Program1 in C:
#include <stdio.h>
int main()
{
int binNum[8]; // Array to read binary number
long dec=0,n=0; // variables used to convert binary to decimal
int k=0,l=0;
long binary=0;
int i=1,j=0,remainder=0;
//reading the binary number in to the array binNum
printf("Please Enter the first binary number with each bit seperate by at least one space : \n");
scanf("%d %d %d %d %d %d %d %d",&binNum[0],&binNum[1],&binNum[2],&binNum[3],&binNum[4],&binNum[5],&binNum[6],&binNum[7]);
//converting the binary number in to decimal
for(k=7;k>=0;k--)
{
dec=(binNum[k]*power(2,l))+dec;
l++;
}
printf("Next 10 binary numbers are as below : \n");
//Printing next 10 binary numbers by incrementing the decimal number.
//and converting the decimal number to binary after increment
for(j=1;j<=10;j++,dec++){
i=1;
remainder=0;
binary=0;
n=dec+1;
while(n != 0) {
remainder = n%2;
n = n/2;
binary= binary + (remainder*i);
i = i*10;
}
printf("%ld \n",binary);
}
return 0;
}
//Power function to calculate the power of 2 numbers.
int power(int c, int d)
{
int pow=1;
int i=1;
while(i<=d)
{
pow=pow*c;
i++;
}
return pow;
}
Actually, program is a executable software that runs on a computer.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images