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

Write a C code that will take a large (predefined) one demensional array of bina

ID: 3672279 • Letter: W

Question

Write a C code that will take a large (predefined) one demensional array of binary numbers and assign each consecutive element to 4 output variables every 100 mili seconds. (the output variable will be updated every 100ms with the next set of 4bit binary from the array)

It should look something like this:

arr[10000] = {0,0,0,1,1,0,1,0,1,1,..........}

counter = 0;

counter ++;

if counter == 100ms

D3 = Arr[0];

D2 = Arr[1];

D1 = Arr[2];

D0 = Arr[3];

if counter == 200ms

D3 = Arr[4];

D2 = Arr[5];

D1 = Arr[6];

D0 = Arr[7];

The code must repeat until all elements in the array has been assigned.

Explanation / Answer

Hi, I have written the code.

Before running this program, Please fill array with 0 and 1

#include <stdio.h>
#include<stdlib.h>

int main(){
  
   int arr[10000] = {1,0,1,0,0,1,1,.............}; // this is predefined array, please fill with 0 and 1
  
   int counter = 0; // counter for milisec
   int D0,D1,D2,D3; // four variables that hold 4 value
   int i=0;
   while(i<10000){
       counter = 0; // initializing counter for each iteration
       D3 = arr[i]; i++; // storing value and incrementing i
       D2 = arr[i]; i++;
       D1 = arr[i]; i++;
       D0 = arr[i]; i++;
      
       // printing four consutive valus
       printf("%d%d%d%d ",D3,D2,D1,D0);
      
       while(counter < 100) // waiting for 100 mili sec
           counter++;
       }
      
       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