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

A binary bar code scan is a bit pattern that contains only 1s and 0s. Write a pr

ID: 3787329 • Letter: A

Question

A binary bar code scan is a bit pattern that contains only 1s and 0s. Write a program that finds the edges of light and dark regions. Process an input bit pattern in the following manner: Assign a 1 to the output bit pattern whenever two consecutive bits (one bit and it’s previous bit) are different Assign a 0 to the output bit pattern whenever two consecutive bit (one bit and it’s previous bit) are the same Assign 0 to the first output bit since there is no previous bit for the first bit

For example, input and output bit pattern of the program that detects the edges might look like the following: Input:   00101101 Output: 00111011


1) Name your program barcode.c. 2) Assume the input contains exactly 8 bits. 3) You can use format specifier "%1d" in scanf to read in a single digit into a variable (or an array element). For example, for input 101011, scanf("%1d", &num) will read in 1 to num. 4) As part of the solution, write and call the function edge() with the prototype

void edge(int n, int a1[], int a2[]);

to perform edge detection. The arguments of the function edge() contain the length of the input and output arrays with the same size, the input array a1, and output array a2.

Explanation / Answer

#include<stdio.h>

void edge(int n, int a1[], int a2[]);

int main(){
   int a1[8],a2[8],i;
   printf("Enter the bar code");
   for(i=0;i<8;i++){
       scanf("%1d",&a1[i]); //reads only one bit at a time
   }
   edge(8,a1,a2); //calling the function edge
  
}

void edge(int n, int a1[], int a2[]){
   a2[0]=0; //as said in the question itself make first bit of a2 to '0'
   int i=1;
   for(i=1;i<n;i++){
       if(a1[i]==a1[i-1]){
           a2[i]=0; //if the current bit and previous bit are same make current bit of a2 '0'
       }else{
           a2[i]=1; //if the current bit and previous bit are different make current bit of a2 '1'
       }
   }
}

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